Spring Boot (2) core annotations

The core of Spring Boot

Entry class and @SpringBootApplication

Spring Boot projects generally have an entry class of *Application , and there will be a main method in the entry class, which is the entry method of a standard Java application.

The @SpringBootApplication annotation is the core annotation of Spring Boot , which is actually a combined annotation:

This annotation mainly combines the following annotations:

1. @SpringBootConfiguration : This is the configuration annotation of the Spring Boot project, which is also a combined annotation:

 It is recommended to use @SpringBootConfiguration instead of @Configuration in Spring Boot projects

2. @EnableAutoConfiguration : Enable automatic configuration, this annotation will cause Spring Boot to automatically configure the configuration items of the project according to the jar package that the project depends on :

a) For example: we add the dependency of spring-boot-starter-web , the dependency of SpringMVC will be introduced into the project, and Spring  Boot will automatically configure tomcat and SpringMVC


3. @ComponentScan : By default , the sibling directory of the class where @SpringBootApplication is located and its subdirectories are scanned .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325994466&siteId=291194637