liveBook · Manning

@SpringBootApplication

As explained in Spring in Action, Sixth Edition

@SpringBootApplication is a Spring Boot annotation that combines configuration, automatic configuration, and component scanning.

@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

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains the annotation’s three composed annotations and stops short of detailing automatic-configuration internals.
Examples
Uses TacoCloudApplication with a main method that calls SpringApplication.run.
What it assumes
Requires a Java class containing a main method and minimal Spring configuration.
What you can do after
Build a Spring Boot bootstrap class that discovers components and starts the application through an executable JAR.
How it connects
Connects configuration classes, automatic configuration, component scanning, Spring components, and SpringApplication.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.