What is @SpringBootApplication in Spring Boot - CodeByAkram

What is @SpringBootApplication in Spring Boot

What is @SpringBootApplication in Spring Boot?

"Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning. This is a convenience annotation that is equivalent to declaring @Configuration, @EnableAutoConfiguration and @ComponentScan."
CodeByAkram SpringBoot

 If you are using spring boot version below 1.2 than you need to add the below annotation in your application.
  1. @Configuration to enable Java-based configuration and mark your class a Configuration class.
  2. @ComponentScan to enable component scanning so that controllers and other components will automatically discovered and registered as bean in Spring's Application Context.
  3. @EnableAutoConfiguration to enable Spring Boot's auto-configuration feature.
But if you using spring boot 1.2 or above version, you just need to add the @SpringBootApplication annotation in your main class and your main class should be in your base package.

@SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiguration



No comments:

Post a Comment