1. 程式人生 > >SpringBoot 專案報錯 spring boot Configuration Annotation Proessor not found in classpath

SpringBoot 專案報錯 spring boot Configuration Annotation Proessor not found in classpath

報錯spring boot Configuration Annotation Proessor not found in classpath

這是因為@ConfigurationProperties(prefix=”author”) 沒有指定classpath時,IDEA提示沒有找到classpath。

而spring boot1.5以上版本@ConfigurationProperties取消location註解

在配置類中採用@Component的方式註冊為元件,然後使用@PropertySource來指定自定義的資源目錄.(本人測試用@Service代替@Component也可以的) 有以下三種解決方案:第一種:

在resource中建立author.properties,並指明@PropertySource(“author.properties”) ,即預設在resource下找此檔案,找到返回一個值,找不到則報錯,報檔案找不到,打不開。

第二種: 在resource下建立config資料夾,把author.properties放在config下,訪問方式為:@PropertySource(“classpath:config/book.properties”)

 直接寫在application.properties中(不建議這麼做,但如果時全域性變數提倡這種方法),當寫在此檔案中時,不需要指明資原始檔路勁,只需要指明字首即可。