Tag Archives: SpringBoot Application

WHAT DOES @ENABLEAUTOCONFIGURATION DO? WHAT ABOUT @SPRINGBOOTAPPLICATION?

What does @EnableAutoConfiguration do? What about @SpringBootApplication?

@EnableAutoConfiguration annotation on a Spring Java configuration class
– Causes Spring Boot to automatically creates beans you need.
– Usually based on classpath contents, can easily override.
@Configuration
@EnableAutoConfiguration
public class MyAppConfig {
public static void main(String[] args) {
SpringApplication.run(MyAppConfig.class, args);
}
}

@SpringBootApplication was available from Spring Boot 1.2
It is very common to use @EnableAutoConfiguration, @Configuration, and @ComponentScan together.
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class MyAppConfig {

}

With @SpringBootApplication annotation
@SpringBootApplication
public class MyAppConfig {

}