What is the purpose of @SpringBootApplication?
Options
- It starts the database that the application will use
- It combines configuration, auto-config and component scan (Correct option)
- It defines a REST endpoint directly on the main class
- It runs the unit tests when the application starts
Answer
It combines @Configuration, @EnableAutoConfiguration and @ComponentScan, marking the main class of the app
Why
Placed on your main class, it is a shortcut for three annotations:
@Configuration: the class can define beans.@EnableAutoConfiguration: turn on Spring Boot's automatic setup.@ComponentScan: scan this package and sub-packages for@Component,@Service...
That is why the main class should live in the top-level package of your project.
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}Remember
Main class annotation = config + auto-config + component scan.