preface

As we’ve seen previously, there are generally two ways to scan a class into an IoC container in Spring: add @Component to the class; The second is to specify the class on the configuration class. In the second class of methods corresponding to the actual is mostly begin with the Enable, for example is @ EnableConfigurationProperties and @ ConfigurationProperties collocation is used.

The source code

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({EnableConfigurationPropertiesRegistrar.class})
public @interface EnableConfigurationProperties {
    String VALIDATOR_BEAN_NAME = "configurationPropertiesValidator"; Class<? >[] value()default {};
}
Copy the code

use

The startup class is also a configuration class.

@Configuration
@EnableConfigurationProperties(YouConfigurationProperties.class)
public class MyConfig {
    // ...
}
Copy the code