Home>Article>Backend Development> What are the core annotations of SpringBoot?

What are the core annotations of SpringBoot?

晓曦&sea
晓曦&sea forward
2020-07-18 16:32:27 6925browse

SpringBoot core annotations include: @SpringBootApplication*, @Configuration, @SpringBootConfiguration, @ComponentScan, @Conditional, etc.

What are the core annotations of SpringBoot?

##1.@SpringBootApplication*

is used for the most most most of the Spring main classes The core annotation, automation configuration file, indicates that this is a SpringBoot project, used to enable various capabilities of SpringBoot.

Equivalent to the combination of the three annotations @SpringBootConfigryation, @EnableAutoConfiguration, and @ComponentScan.

2.@EnableAutoConfiguration

Allow SpringBoot to automatically configure annotations. After turning on this annotation, SpringBoot can configure the annotation according to the current Packages or classes on the classpath to configure Spring Beans.

For example:

There is the MyBatis Jar package in the current path, and the MyBatisAutoConfiguration annotation can configure each Spring Bean of Mybatis according to the relevant parameters.

3.@Configuration

An annotation added by Spring 3.0 to replace the applicationContext.xml configuration file. All things that can be done in this configuration file can be registered through the class where this annotation is located.

4.@SpringBootConfiguration

The variant of @Configuration annotation is only used to modify the configuration of Spring Boot. .

5.@ComponentScan

An annotation added by Spring 3.1 to replace component- in the configuration file scan configuration, enable component scanning, automatically scan the @Component annotation under the package path to register the bean instance and put it in the context (container).

6.@Conditional

An annotation added by Spring 4.0 to identify a Spring Bean or Configuration configuration file, the configuration will only be opened when the specified conditions are met

##7.@ConditionalOnBeanCombined @Conditional annotation, when the container Configuration is enabled only if there is a specified Bean in it.

8.@ConditionalOnMissingBeanCombines the @Conditional annotation. When there is no value in the container, the Bean can be configured. .

9.@ConditionalOnClassCombining the @Conditional annotation, the configuration can only be enabled when there is a specified Class in the container.

10.@ConditionalOnMissingClassCombined @Conditional annotation, the configuration can only be enabled when no Class is specified in the container.

11.@ConditionOnWebApplicationCombined @Conditional annotation, the configuration can only be enabled when the current project type is a WEB project.

There are three types of projects:

① ANY: Any Web project

② SERVLET: Servlet Web project

③ REACTIVE: based on reactive -base Web project

12. @ConditionOnNotWebApplicationcombination of @Conditional annotation, the current project type is not a WEB project Only then can the configuration be enabled.

13.@ConditionalOnPropertyCombines the @Conditional annotation only when the specified property has the specified value Turn on configuration.

14.@ConditionalOnExpressionCombined @Conditional annotation, the configuration can be enabled only when the SpEl expression is true .

15.@ConditionOnJavaCombined @Conditional annotation, when the running Java JVM is in the specified version range Just open the configuration.

16.@ConditionalResourceCombined @Conditional annotation, the configuration will only be enabled when there is a specified resource in the class path .

17.@ConditionOnJndiCombines the @Conditional annotation to enable the configuration when the specified JNDI exists.

18.@ConditionalOnCloudPlatform

Combined @Conditional annotation, the configuration can only be enabled when the specified cloud platform is activated.

19.@ConditiomalOnSingleCandidate

Combined @Conditional annotation, when the specified Class has only one Bean in the container, Or there are multiple ones at the same time but the configuration is enabled only when it is preferred.

20.@ConfigurationProperties

is used to load additional configurations (such as .properties files), available in @ Configuration annotation class or @Bean annotation method. You can take a look at several ways Spring Boot reads configuration files.

21.@EnableConfigurationProperties

Generally used with the @ConfigurationProperties annotation to enable the @ConfigurationProperties annotation to configure the Bean support.

22.@AntoConfigureAfter

is used on the automatic configuration class, that is, the automatic configuration class needs to be used in another After the specified automatic configuration class is configured. For example, Mybatis's automatic configuration class needs to be installed after the data source automatic configuration class.

23.@AutoConfigureBefore

## is used on the automatic configuration class, that is, the automatic configuration class needs to be used in another Before the specified auto-configuration class is configured.

24.@Import##Spring 3.0 adds annotations to import one or more @Configuration annotation modifications configuration class.

25.@IMportReSourceSpring 3.0 adds annotations to import one or more Spring configuration files. This is very useful for Spring Boot compatible old projects. Some configuration files cannot be configured through java config.

The above is the detailed content of What are the core annotations of SpringBoot?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete