@EnableConfigurationProperties


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM