The use and introduction of SpringBoot annotations

Introduction of some annotations in SpringBoot

1.ConfigurationProperties:

Function: Tell SpringBoot to bind all the attributes in this class to the configuration related to the configuration file.
Bind the data in the configuration file

2.PropertySource:

Function: Load the configuration file at the specified location, but if there is the same matching data elsewhere, other data may be bound first
Bind the configuration file data at the specified location

3.Conditional derived annotation

Function: The derived annotation of the native annotation Conditional in the Spring annotation is used to determine the condition to determine whether the annotation is valid

//这是HttpEncodingAutoConfiguration 类上的部分注解,全部都是用于判断,判断为true的情况才会使HttpEncodingAutoConfiguration 生效
@ConditionalOnWebApplication(
    type = Type.SERVLET
)
@ConditionalOnClass({
    
    CharacterEncodingFilter.class})
@ConditionalOnProperty(
    prefix = "server.servlet.encoding",
    value = {
    
    "enabled"},
    matchIfMissing = true
)
public class HttpEncodingAutoConfiguration {
    
    }

//这是HttpEncodingAutoConfiguration上的ConditionalOnProperty注解底层,可以看到产生作用的是Conditional注解。
@Retention(RetentionPolicy.RUNTIME)
@Target({
    
    ElementType.TYPE, ElementType.METHOD})
@Documented
@Conditional({
    
    OnPropertyCondition.class})
public @interface ConditionalOnProperty {
    
    }

Guess you like

Origin blog.csdn.net/TreeCode/article/details/108080139