1、@SpringBootApplication
This is the most core annotation of Spring Boot. It is used on the main Spring Boot class to identify that this is a Spring Boot application and is used to enable Spring Boot's various capabilities.
In fact, this annotation is a combination of these three annotations @SpringBootConfiguration
, @EnableAutoConfiguration
and @ComponentScan
these three annotations can also be used instead of @SpringBootApplication
annotations.
2、@EnableAutoConfiguration
Allow Spring Boot to automatically configure annotations. After turning on this annotation, Spring Boot can configure Spring Beans according to the packages or classes under the current classpath.
For example, there is the Mybatis JAR package in the current classpath, and the MybatisAutoConfiguration
annotations can configure each Spring Bean of Mybatis according to the relevant parameters.
3、@Configuration
This is an annotation added by Spring 3.0 to replace the applicationContext.xml configuration file. All the things that can be done in this configuration file can be registered through the class of this annotation.
4、@SpringBootConfiguration
This annotation is a variant of the @Configuration annotation, which is only used to modify the Spring Boot configuration, or it can be beneficial to the subsequent expansion of Spring Boot.
5、@ComponentScan
This is an annotation added by Spring 3.1 to replace the component-scan configuration in the configuration file to enable component scanning, that is, to automatically scan the @Component annotation in the package path to register bean instances in the context.
6、@Conditional
This is a new annotation added by Spring 4.0. It is used to identify a Spring Bean or Configuration file, and the configuration is started when the specified conditions are met.
7、@ConditionalOnBean
Combination of @Conditional
annotations, when there is a specified Bean in the container, the configuration is opened.
8、@ConditionalOnMissingBean
Combination @Conditional
annotations, in @ConditionalOnBean
contrast to annotations, start the configuration when there is no specified Bean in the container.
9、@ConditionalOnClass
Combination of @Conditional
annotations, the configuration is turned on when there is a specified Class in the container.
10、@ConditionalOnMissingClass
Combination @Conditional
annotations, in @ConditionalOnMissingClass
contrast to annotations, enable configuration only when there is no specified Class in the container.
11、@ConditionalOnWebApplication
Combination @Conditional
notes, the current project type is WEB project to start the configuration.
The current project has the following 3 types.
enum Type {
/**
* Any web application will match.
*/
ANY,
/**
* Only servlet-based web application will match.
*/
SERVLET,
/**
* Only reactive-based web application will match.
*/
REACTIVE
}
12、@ConditionalOnNotWebApplication
Combination @Conditional
annotations, @ConditionalOnWebApplication
contrary to annotations, the configuration is started only when the current project type is not a WEB project.
13、@ConditionalOnProperty
Combination @Conditional
annotation, when the specified attribute has the specified value, the configuration is opened.
14、@ConditionalOnExpression
Combination of @Conditional
annotations, the configuration is only enabled when the SpEL expression is true.
15、@ConditionalOnJava
Combination of @Conditional
annotations, when the running Java JVM is in the specified version range, the configuration is turned on.
16、@ConditionalOnResource
Combination @Conditional
annotations, when there is a specified resource in the class path, the configuration is opened.
17 、 @ ConditionalOnJndi
Combination of @Conditional
annotations, the configuration is only opened when the specified JNDI exists.
18、@ConditionalOnCloudPlatform
Combination of @Conditional
annotations, the configuration is only enabled when the specified cloud platform is activated.
19、@ConditionalOnSingleCandidate
Combined @Conditional
annotation, when the specified class has only one Bean in the container, or there are multiple at the same time but it is the first choice, the configuration is turned on.
20、@ConfigurationProperties
Used to load additional configuration (such as .properties files), which can be used in @Configuration
annotation classes or @Bean
annotation methods.
21、@EnableConfigurationProperties
It is generally @ConfigurationProperties
used in conjunction with annotations to enable support for @ConfigurationProperties
annotation configuration beans.
22、@AutoConfigureAfter
Used on the auto-configuration class, it means that the auto-configuration class needs to be configured after the other-specified auto-configuration class is configured.
For example, the automatic configuration class of Mybatis needs to be after the automatic configuration class of the data source.
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class MybatisAutoConfiguration {
23、@AutoConfigureBefore
This is @AutoConfigureAfter
contrary to the use of annotations, which means that the auto-configuration class needs to be configured before the auto-configuration class that is otherwise specified.
24、@Import
This is a new annotation added by Spring 3.0, which is used to import one or more @Configuration
annotation-modified classes, which are used in Spring Boot.
25、@ImportResource
This is a new annotation added by Spring 3.0 to import one or more Spring configuration files. This is very useful for Spring Boot compatible old projects, because some configurations cannot be configured in the form of Java Config and can only be imported using this annotation.