@SpringBootApplication Annotation

@SpringBootApplication attribute is used to enable auto-configuration, component scan and to define extra configuration in a single application class.

@SpringBootApplication 
public class Application {  
   public static void main(String[] args) { 
      SpringApplication.run(Application.class, args); 
   } 
}

Though the same things can be achieved using following annotations individually

  • @EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism automatically configure your Spring application based on the jar dependencies that you have added. For example, if HSQLDBis configured in our classpath, and you have not manually configured any database connection beans, then Spring Boot auto-configures an in-memory database. Auto-configuration is non-invasive. For example, if you add your own DataSource bean, the default embedded database support backs away. If you need to find out what auto-configuration is currently being applied, start your application with the --debug switch. If we dont want to load specific auto-configuration classes then we can use the exclude attribute of @EnableAutoConfiguration to disable them, i.e.
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
    public class MyConfiguration {
}
  • @ComponentScan: enable @Component scan on the package where the application is located. This attribute is generally used (put) in our main class. For example, if you are writing a JPA application, the package of the  @SpringBootApplication  annotated class is used to search for @Entity items. Using a root package also allows component scan to apply only on your project.
  • @Configuration: Allow to register extra beans in the context or import additional configuration classes. Spring generally recommend that your primary source be a single @Configuration class. Usually the class that defines the main method is a good candidate as the primary @Configuration. You need not to put all your   @Configuration into a single class. The @Import annotation can be used to import additional configuration classes. Alternatively, We can use   @ComponentScan to automatically pick up all Spring components, including   @Configuration classes.

 

GIT : NA

Hope this clears your doubt!!