Springboot~@EnableConfigurationProperties注解的作用


  • @Component || @Controller || @Service
  • @Configuration
  • @ConfigurationProperties
  • @EnableConfigurationProperties

以上注解的關系梳理:
  @Component || @Controller || @Service 用來定義spring的bean。

作用:
  @EnableConfigurationProperties的作用: 使@ConfigurationProperties 注解的類生效。

正確的bean的屬性配置加載

 

錯誤bean的屬性配置加載

糾正: 錯誤bean的屬性配置加載

 

結果:
  如果一個配置類只配置@ConfigurationProperties注解,而沒有使用@Component,那么在IOC容器中是獲取不到properties 配置文件轉化的bean。
@EnableConfigurationProperties 是把指定類的屬性又注入了一次。


免責聲明!

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



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