Spring Boot autoconfiguration sets up application components when the application starts. It makes reasonable choices based on libraries on the classpath, environment variables, and other conditions, so you can get useful behavior without writing the equivalent Java or XML configuration yourself. section 1.1
It builds on two familiar Spring ideas: component scanning discovers classes to register as beans, and autowiring supplies the beans they depend on. Autoconfiguration goes further by configuring components needed to make available libraries work together. You can still add explicit configuration when the automatic choices do not meet your needs. section 1.1 section 1.5
Listing 1.2 The Taco Cloud bootstrap class
package tacos;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication #1
public class TacoCloudApplication {
public static void main(String[] args) {
SpringApplication.run(TacoCloudApplication.class, args); #2
}
}
The bootstrap class shows the small amount of code needed to start the application. Its @SpringBootApplication annotation includes @EnableAutoConfiguration; SpringApplication.run() creates the application context. section 1.2.2
Adding starter dependencies makes the effect visible:
- With Web and Thymeleaf starters, startup configuration enables Spring MVC, embedded Tomcat, and a Thymeleaf view resolver. section 1.3.6
- With the Spring Security starter, startup configuration supplies basic security. Requests require authentication, a login page appears, and a generated password is written to the log. section 5.1
The practical approach is to add the dependencies your application needs, run it, and see what Boot provides before writing configuration. Autoconfiguration removes setup work; it does not replace the code that implements your application’s features. section 1.3.6 section 1.4.2
