參考: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