- @Component || @Controller || @Service
- @Configuration
- @ConfigurationProperties
- @EnableConfigurationProperties
以上注解的關系梳理:
@Component || @Controller || @Service 用來定義spring的bean。
作用:
@EnableConfigurationProperties的作用: 使@ConfigurationProperties 注解的類生效。
正確的bean的屬性配置加載
錯誤bean的屬性配置加載
糾正: 錯誤bean的屬性配置加載
結果:
如果一個配置類只配置@ConfigurationProperties注解,而沒有使用@Component,那么在IOC容器中是獲取不到properties 配置文件轉化的bean。
@EnableConfigurationProperties 是把指定類的屬性又注入了一次。