参考:https://www.jianshu.com/p/7f54da1cb2eb
使用 @ConfigurationProperties 注解的类生效。
如果一个配置类只配置@ConfigurationProperties注解,而没有使用@Component,那么在IOC容器中是获取不到properties 配置文件转化的bean。
==> @EnableConfigurationProperties 相当于把使用 @ConfigurationProperties 的类进行了一次注入。
@ConfigurationProperties
与
@EnableConfigurationProperties
的关系:
@EnableConfigurationProperties
:
/**
* Enable support for {@link ConfigurationProperties} annotated beans.
* {@link ConfigurationProperties} beans can be registered in the standard way (for
* example using {@link Bean @Bean} methods) or, for convenience, can be specified
* directly on this annotation.
*
* @author Dave Syer
*/
当
@EnableConfigurationProperties
注解应用到你的
@Configuration
时, 任何被
@ConfigurationProperties
注解的beans将自动被Environment属性配置。 这种风格的配置特别适合与SpringApplication的外部YAML配置进行配合使用。
@EnableConfigurationProperties=@ConfigurationProperties+@Component