MENU

Resolving Spring Boot Configuration Annotation Processor Not Configured Warning in IntelliJ IDEA

2021 年 10 月 03 日 • 阅读: 5182 • 后端

在 IDEA 2021.2.2 中编写 Spring Boot 项目,打开使用了 @ConfigurationProperties 注解的类时,标签页下方会出现 Spring Boot Configuration Annotation Processor not configured 的提示,而提示给出的文档链接已经 404 了。

搜索后发现 Spring Boot Configuration Annotation Processor 会扫描被 @ConfigurationProperties 注解的类,以此生成配置元数据,这些元数据可以被编译器读取用于 application.properties 中配置项的自动补全和错误检查。

根据 Spring Boot 文档,只要引入相应依赖并重新编译项目便可生成配置元数据。但即便如此,IDEA 的提示有时并不消失,此时需要重载项目。之后,提示文字转为 Re-run Spring Boot Configuration Annotation Processor to update generated metadata,并且背景由红色转为深灰。这个提示只是在说,如果更改了类,记得重新编译更新元数据,并非警告,无需理会。此时打开 application.properties 就会发现自动补全已经可以正常使用了。网络上的一些文章说的打开 IDEA 设置里的 Enable annotation processing 实际是另一个功能,与此无关。

Maven

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

添加依赖后执行 Lifecycle -> clean -> compile -> Reload project

元数据生成位置 target/classes/META-INF/spring-configuration-metadata.json

Gradle

dependencies {
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
}

添加依赖后执行 Tasks -> other -> compileJava -> Reload Gradle Project

元数据生成位置 build/classes/java/main/META-INF/spring-configuration-metadata.json

References

TG 大佬群 QQ 大佬群

返回文章列表 文章二维码
本页链接的二维码
打赏二维码
添加新评论

Loading captcha...