SpringBoot中@ConfigurationProperties提示:Configuration Annotation Processor not found in classpath

在Spring Boot中,當使用@ConfigurationProperties定義自動配置類時,IDEA會提示:

Spring Boot Configuration Annotation Processor not found in classpath

雖然對執行程序沒有什麼影響,但看到這個提示還是想解決一下的,解決方案是在pom.xml文件中添加如下依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

引起該提示的原因是:高版本的Spring Boot中@ConfigurationProperties註解去掉了localhost屬性,導致發生這個錯誤,所以建議還是直接從配置文件中讀取字段而不是獲取對象。

而spring-boot-configuration-processor的功能,官方給出的解釋是:通過使用spring-boot-configuration-processor jar,你可以從被@ConfigurationProperties註解的節點輕鬆的產生自己的配置元數據文件。y

也就是說自定義的元數據文件使用註解方式獲取,需要先引入這個依賴。

原文鏈接:《SpringBoot中@ConfigurationProperties提示:Configuration Annotation Processor not found in classpath

精品SpringBoot 2.x視頻教程

《Spring Boot 2.x 視頻教程全家桶》,精品Spring Boot 2.x視頻教程,打造一套最全的Spring Boot 2.x視頻教程。


程序新視界

公衆號“程序新視界”,一個讓你軟實力、硬技術同步提升的平臺

csdn-微信公衆號

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章