Spring Boot configuration annotation processor not found in classpath
Spring Boot configuration annotation processor not found in classpath问题产生今天在使用Spring Boot开发的过程中,使用了Druid连接池,但在写Druid相关的Java代码时,提示Spring Boot configuration annotation processor not found in...
Spring Boot configuration annotation processor not found in classpath
问题产生
今天在使用Spring Boot开发的过程中,使用了Druid连接池,但在写Druid相关的Java代码时,提示Spring Boot configuration annotation processor not found in classpath,如下截图所示:
问题解决
问了下度娘,在IDEA中,classpath中找不到Spring Boot配置注解,默认是在resources/application.properties文件中,但是一些非全局的配置,单独归类并写在其他的一个文件中是更为合理的。那问题来了,如果我把spring.datasource.druid的一些配置写在resources/application.properties文件里,会不会正常呢,于是试了下,问题还是存在。。。。。
那会不会是我没有指定具体的文件呢,因为spring.datasource.druid的一些配置是写在application-dev.properties文件中的,于是我在注解@ConfigurationPropertie的上方加了注解@PropertySource(“classpath:application-dev.properties”),用鼠标试了,是可以正确定位到的,然后问题还是存在。
再看截图,
打开连接https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor,看下到底是什么回事,发现直接给了解决方法,那就是在pom.xml文件中加入依赖spring-boot-configuration-processor,至此问题解决。代码如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
那原因又是什么呢,根据提示信息….not found in classpath,查询此注解的使用关于怎么指定classpath,进而查询location,Spring Boot1.5以上版本@ConfigurationProperties取消location注解,反正就是在1.5版本后改变了@ConfigurationProperties注解的使用,我用的是2.0.1版本,自然会有这个问题。最后还是附上连接中描述的截图,有兴趣的可以进去看下。
更多推荐
所有评论(0)