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

问题

Springboot1.5以上版本,在使用 @ConfigurationProperties注解的时候会提示Spring Boot Configuration Annotation Processor not found in classpath,

原因

这是因为新版本已经取消了对location的支持,替代方案是使用
@Configuration@PropertySource进行组合使用,例如:

@Primary
@Configuration
@PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true)

如果要使用指定属性前缀Prefix,这时候还会使用到@ConfigurationProperties,提示依然会存在

解决方案

在POM文件中增加依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-configuration-processor</artifactId>
  <optional>true</optional>
</dependency>
posted @ 2021-03-10 11:10  至安  阅读(1188)  评论(0)    收藏  举报