java-在类路径中找不到@ConfigurationProperties Spring Boot配置注释处理器
我尝试在Spring Boot中完成自定义属性。
我试图通过IntelliJ IDEA 2016.3创建一个简单的项目:
1.使用Spring Boot Initializer创建一个新的Gradle项目(我一点都没有检查)。
2.创建了一个新类my。
3.当我用@ConfigurationProperties对其进行注释时,出现了下一个通知:
文档说我应该在我的项目中添加以下内容:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
compileJava.dependsOn(processResources)
之后,我尝试重建项目并在设置中启用注释处理器,但通知没有消失。 完成也不起作用(我创建了一个字符串my)。
7个解决方案
22 votes
我有同样的问题。 我使用想法2017.2和gradle 4.1,一些博客说您应该添加:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
但是我将其更改为:
dependencies {
compile "org.springframework.boot:spring-boot-configuration-processor"
}
警告不见了。
Icex answered 2020-07-11T09:20:32Z
11 votes
根据Spring Boot的文档,自Gradle 4.6以来的正确配置是
dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ...
}
但是IntelliJ IDEA不支持annotationProcessor范围(尚未)。 如果您想提请注意此问题,请升级IDEA-187868。
naXa answered 2020-07-11T09:20:57Z
10 votes
我忘了添加propdeps插件。 但是,我记得即使使用2016.3上的插件它也对我不起作用,因此正如@CrazyCoder所述,请尝试降级Gradle或下载新的2017.1版本(详细信息)。
当您解决此问题时,也可能会收到Re-run Spring Boot Configuration Annotation Processor to update generated metadata。 为此,请单击Refresh all Gradle projects(在Gradle侧面菜单中)。
Feeco answered 2020-07-11T09:21:22Z
4 votes
在IntelliJ的2018.3版本中,我通过以下方式解决了此问题(根据本文档):
对于Gradle 4.5及更早版本,相关性应在 compileOnly配置,如以下示例所示:
dependencies {
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
}
在Gradle 4.6及更高版本中,相关性应在 注解处理器配置,如以下示例所示:
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
AR1 answered 2020-07-11T09:21:51Z
4 votes
我发生这种情况的原因有两个:
仔细检查是否在IDEA中选择(启用)设置:“首选项”->“注释处理器”->“启用注释处理”。
更新您的Idea之后,请检查您的插件并进行更新。 碰巧插件与您的新IDEA版本不兼容,因此只需单击以更新它们。
Victor Schurenko answered 2020-07-11T09:22:20Z
1 votes
IntelliJ 2018.1.2版存在相同的问题。 为了使它工作,我还必须定义spring-boot-configuration-processor的实际版本:
compile('org.springframework.boot:spring-boot-configuration-processor:2.0.1.RELEASE')
vargapeti answered 2020-07-11T09:22:40Z
0 votes
以下对我有用的作品:
buildscript {
repositories {
jcenter()
maven { url 'https://repo.jenkins-ci.org/public/' }
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath "io.spring.gradle:propdeps-plugin:0.0.9.RELEASE"
}
}
...
apply plugin: 'propdeps'
apply plugin: 'propdeps-eclipse'
apply plugin: 'propdeps-idea'
...
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:2.0.0.RELEASE'
}
}
...
dependencies {
compile "org.springframework.boot:spring-boot-starter"
compile "org.springframework.boot:spring-boot-starter-actuator"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" // for @ConfigurationProperties, make sure compileJava.dependsOn(processResources)
...
}
compileJava.dependsOn(processResources)
Dirk Hoffmann answered 2020-07-11T09:22:59Z