Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand spring boot starter

Shulou Source: shulou.com Published: 2022-06-02 01:58:22 09月27日 Update

How to understand spring boot starter, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Spring boot stater:

Native spring boot systems contain many default starter. Such as rabbit,jdbc and so on. It's all stated in spring-boot-autoconfigure. There is a corresponding XXXAutoConfiguration declaration in the corresponding spring.factories. When the system starts, it will actively load the qualified Configuration to complete the initialization.

Automatic configuration, bean configuration based on java code, can be used together with @ Configuration,@Bean to create a java code-based configuration instead of the corresponding xml configuration.

In the XXXAutoConfiguration class, some instances are automatically created and handed over to the spring container to complete the automatic registration of bean.

Automatically configure conditional dependencies. There are some commonly used conditional dependency annotations in Springboot:

1.@ConditionOnBean, which is instantiated only if a bean exists in the current context.

2.@ConditionOnClass, which is instantiated only if a class is on the classpath.

3.@ConditionOnExpression, which is instantiated only when the expression is true.

4.@AutoConfigureAfter, instantiate the bean after the automatic configuration of the bean

5.@AutoConfigureBefore, instantiate a bean before completing its automatic configuration.

6.@ConditionalOnProperty, according to the properties of the configuration file to determine whether to load the instantiated bean. MatchIfMissing, when the property is true, the configuration file is missing the corresponding property value. This bean is also instantiated.

If you want to extend a class yourself, and there is already a default AutoConfiguration, you can customize excludeAutoConfiguration to exclude the system's default XXXAutoConfiguration class.

Customize the implementation class of EnvironmentPostProcessor, then find the PropertySource that contains spring.autoconfigure.exclude [0], and add an exclusion to configure XXXAutoConfiguration. Then initialize the system with the custom AutoConfiguration.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Configuration instance system properties time condition code file comment help clear active up and down context two content container this commonly used article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS vpn Microsoft Shulou Tech Info