@SpringBootApplication marks a class as the Spring Boot application’s bootstrap and configuration class. It combines configuration, automatic configuration, and component scanning in one annotation. section 1.2.2
The annotation combines three framework behaviors:
- @SpringBootConfiguration designates the class as a Java-based configuration class. section 1.2.2
- @EnableAutoConfiguration asks Spring Boot to configure components it determines the application needs. section 1.2.2
- @ComponentScan discovers and registers annotated components such as @Component, @Controller, and @Service. section 1.2.2
Bootstrap a Taco Cloud application
@SpringBootApplication public class TacoCloudApplication { public static void main(String[] args) { SpringApplication.run(TacoCloudApplication.class, args); } } The main method runs when the executable JAR starts; SpringApplication.run performs the application bootstrap. section 1.2.2
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
}
}
View the complete bootstrap class listing, including its package, imports, annotation, and main method. section 1.2.2
