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 {

}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>