Fee*_*eco 46 java spring intellij-idea spring-boot
我尝试在Spring Boot中完成自定义属性.
我尝试通过IntelliJ IDEA 2016.3创建一个简单的项目:
1.使用Spring Boot Initializer创建了一个新的Gradle项目(我没有检查任何内容).
2.创建了一个新课程Properties
.
3.当我用它注释时@ConfigurationProperties
,下一个通知出现了:
文档说我应该在我的项目中添加以下内容:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
compileJava.dependsOn(processResources)
Run Code Online (Sandbox Code Playgroud)
之后,我尝试重建项目并在设置中启用注释处理器,但通知尚未消失.完成也不起作用(我创建了一个字符串my
).
小智 24
我有同样的问题.我使用idea 2017.2和gradle 4.1,有些博客说你应该添加:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
Run Code Online (Sandbox Code Playgroud)
但我把它改成了这个:
dependencies {
compile "org.springframework.boot:spring-boot-configuration-processor"
}
Run Code Online (Sandbox Code Playgroud)
警告消失了.
naX*_*aXa 12
根据Spring Boot docs,自Gradle 4.6起的正确配置是
dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ...
}
Run Code Online (Sandbox Code Playgroud)
但是IntelliJ IDEA尚不支持annotationProcessor
范围。如果您想提请注意此问题,请升级IDEA-187868。
Fee*_*eco 10
我忘了添加propdeps-plugin.但是,我记得即使在2016.3上使用插件它也不适合我.所以正如@CrazyCoder所提到的,尝试降级Gradle或下载新的2017.1版本(详情).
您也可以Re-run Spring Boot Configuration Annotation Processor to update generated metadata
在解决此问题时收到.为此,单击Refresh all Gradle projects
(在Gradle侧面菜单中).
Ole*_*kov 10
在 maven 项目中帮助添加依赖 spring-boot-configuration-processor 并使用 @EnableConfigurationProperties(AppProperties.class) 标记主类。
也许有人会帮忙。
对于那些使用 maven 的人,Intellij 仍然对添加依赖不满意。似乎annotationProcessorPaths
通过添加maven-compiler-plugin
终于驯服了野兽。
确保version
匹配您的 spring 依赖项。我怀疑它已经存在于您的有效 POM 中。
原因:我使用了一个自定义的 parent-pom,其中设置了一个 mapstruct 注释处理器annotationProcessorPaths
,这实际上触发了 IntelliJ 要求手动指定所有其他注释处理器。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.0.4.RELEASE</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
对于 Kotlin 项目,从 Gradle 4.6 开始的工作配置是使用注解处理器
apply plugin: "kotlin-kapt"
dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")
compileOnly("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")
}
Run Code Online (Sandbox Code Playgroud)
在 IntelliJ 2018.3 版本中,我通过以下方式解决了这个问题(根据本文档):
对于 Gradle 4.5 及更早版本,应在 compileOnly 配置中声明依赖项,如以下示例所示:
Run Code Online (Sandbox Code Playgroud)dependencies { compileOnly "org.springframework.boot:spring-boot-configuration-processor" }
对于 Gradle 4.6 及更高版本,应在 annotationProcessor 配置中声明依赖项,如以下示例所示:
Run Code Online (Sandbox Code Playgroud)dependencies { annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" }
对于使用 Maven 或 Gradle 的用户,只需添加对spring-boot-configuration-processor的依赖即可。
马文:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
Gradle 4.5 及更早版本
dependencies {
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
}
Run Code Online (Sandbox Code Playgroud)
Gradle 4.6 及更高版本
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息: “使用注释处理器生成您自己的元数据” https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-configuration-metadata.html#configuration -元数据注释处理器
小智 5
我发生这种情况的原因有两个:
归档时间: |
|
查看次数: |
39318 次 |
最近记录: |