ConfigurationProperties 注解常见错误

➢ 在 ConfigInfo 类中使用了 ConfigurationProperties 注解后,IDEA 会出现一个警告,
不影响程序的执行
错误提示:
Re-run Spring Boot Configuration Annotation Processor to update generated metadata

➢ 点击 open documentnation 跳转到网页,在网页中提示需要加一个依赖,我们将这
个依赖拷贝,粘贴到 pom.xml 文件中

org.springframework.boot spring-boot-configuration-processor true

不使用@Component注解就会报出红框内的错误:Not registered via @EnableConfigurationProperties or marked as Spring component

此时需要添加@Component注解声明将这个组件添加到容器才可以被使用

“当这个组件是容器中的组件时,才能使用容器提供的@ConfigurationProperties功能”

posted @ 2020-11-10 19:28  祖安七省文状元  阅读(890)  评论(0)    收藏  举报