Current location - Health Preservation Learning Network - Healthy weight loss - The core 25 notes of Spring Boot are all dry goods!
The core 25 notes of Spring Boot are all dry goods!
25 core opinions of Spring Boot

1 ,@ spring boot application

This is the core annotation of Spring Boot, which is used in the main class of Spring Boot to identify that this is an application of Spring Boot and to open various capabilities of Spring Boot.

In fact, this annotation is a combination of three annotations: @SpringBootConfiguration, @EnableAutoConfiguration and @ComponentScan, which can also be used instead of @SpringBootApplication annotation.

2. @ Enable automatic configuration

Allow Spring Boot to automatically configure comments. When this annotation is enabled, Spring Boot can configure Spring Bean according to the packages or classes in the current classpath.

For example, if there is a JAR package Mybatis in the current classpath, the MybatisAutoConfiguration annotation can configure each Spring Bean of Mybatis according to relevant parameters.

3. @ Configuration

This is a comment added by Spring 3.0 to replace the applicationContext.xml configuration file. Everything that can be done in this configuration file can be registered through the class to which this comment belongs.

4 、@SpringBootConfiguration

This annotation is a variant of the @Configuration annotation, which is only used to decorate the configuration of Spring Boot, and can also be beneficial to the subsequent expansion of Spring Boot.

5. @ component scanning

This is a comment added by Spring 3. 1, which is used to replace the component-scan configuration in the configuration file, start component scanning, that is, automatically scan the @Component comment under the package path, and register the bean instance into the context.

For the first five annotations, please refer to the Detailed Explanation of Three Core Annotations of Spring Boot in this article.

6. @ Conditional

This is a new note in Spring 4.0, which is used to identify a Spring Bean or configuration file, and the configuration will not be opened until the specified conditions are met.

7 、@ ConditionalOnBean

Combines the @Conditional annotation to open the configuration only when the specified Bean exists in the container.

8 、@ ConditionalOnMissingBean

In contrast to the @Conditional Bean annotation, combining the @ conditional annotation opens the configuration when there is no specified Bean in the container.

9 、@ ConditionalOnClass

Combines the @Conditional annotation to open the configuration only if there is a specified class in the container.

10 ,@ conditionalomissingclass

Contrary to the @ConditionalOnMissingClass annotation, the combination @ Conditional annotation opens the configuration when there is no specified class in the container.

1 1 ,@ ConditionalOnWebApplication

Combination @ conditional comments, the current project type is WEB project open configuration.

There are currently three types of projects.

Enumeration type {

}

12 ,@ ConditionalOnNotWebApplication

The combination of @Conditional annotation, contrary to @ConditionalOnWebApplication annotation, only opens the configuration when the current project type is not a WEB project.

13 ,@ conditional property

Combines the @Conditional annotation to open the layout only when the specified attribute has the specified value.

14 ,@ conditional expression

Combines the @Conditional annotation and opens the configuration when the SpEL expression is true.

15 ,@ ConditionalOnJava

When the running Java JVM is within the specified version range, open the configuration with the @Conditional annotation.

16 ,@ conditional resource

Combines the @Conditional annotation to open the configuration only when there are specified resources under the classpath.

17 ,@ ConditionalOnJndi

When the specified JNDI exists, combine the @Conditional annotation to open the configuration.

18 ,@ conditionalonludplatform

Combined with @Conditional annotation, the configuration will only be opened when the specified cloud platform is activated.

19 ,@ conditionalonsingcandidate

Combined with the @Conditional annotation, open the configuration when the specified class has only one Bean in the container, or there are multiple beans at the same time, but it is the first choice.

20. @ Configure Properties

Used to load additional configurations (such as. Property file), which can be used on @Configuration annotation classes or @Bean annotation methods.

2 1 、@EnableConfigurationProperties

Generally, it should be used with the @ConfigurationProperties annotation to support the @ConfigurationProperties annotation configuration Bean.

22. @ After automatic configuration

Used for automatic configuration class, indicating that the automatic configuration class needs to be configured after another specified automatic configuration class.

For example, the automatic configuration class of Mybatis needs to be after the automatic configuration class of the data source.

23. Before @ Automatic Configuration

This is contrary to the use of the @AutoConfigureAfter annotation, indicating that the autoconfiguration class needs to be configured before another specified autoconfiguration class.

24. @ Import

This is a new annotation in Spring 3.0, which is used to import one or more classes decorated by the @Configuration annotation. This annotation is widely used in Spring Boot.

25 、@ImportResource

This is a new comment added by Spring 3.0 to import one or more Spring configuration files. This is very useful for Spring Boot to be compatible with old projects, because some configurations can only be imported with this comment, because they cannot be configured in the form of Java Config.

Welcome Java engineers and friends to join Java High Concurrency: 957734884, and provide free Java architecture learning materials (including high availability, high concurrency, high performance and distribution, Jvm performance tuning, Spring source code, MyBatis, Netty, Redis, Kafka, MySQL, Zookeeper, Tomcat, Docker, Dubbo, Nginx and other knowledge points) to make rational use of every point. Fight hard while you are young, and give yourself an explanation in the future!