Intellij IDEA抱怨无法解决弹簧启动属性,但它们可以正常工作 [英] Intellij IDEA complains cannot resolve spring boot properties but they work fine

查看:205
本文介绍了Intellij IDEA抱怨无法解决弹簧启动属性,但它们可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法解析配置属性'...

Can not resolve configuration property '...

我可以通过@Value注释或通过自动装配的环境访问我的属性.但是我自己定义的所有属性在IDEA中都会收到此警告.我应该怎么做才能使IDEA认识到这些并且不打扰我?

I have no problem accessing my properties through the @Value annotation or through an autowired Evironment. But all of my own defined properties get this warning in IDEA. What should I be doing to get IDEA to recognize these and not bother me?

推荐答案

为了让IntelliJ IDEA知道您的Spring Boot属性,您可以在项目中定义 Spring Boot配置元数据.

In order for IntelliJ IDEA to know your Spring Boot properties, you can define Spring Boot configuration metadata in your project.

如果可以对属性使用@ConfigurationProperties注释的类,则可以将Spring Boot配置注释处理器添加到类路径中,并且IntelliJ IDEA将在targetout中为您生成配置元数据:

If you can use a @ConfigurationProperties-annotated class for your properties, you can add the Spring Boot configuration annotation processor to your classpath and IntelliJ IDEA will generate the configuration metadata for you in target or out:

Maven:

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

成绩:

implementation 'org.springframework.boot:spring-boot-configuration-processor'

选项2:

自己创建配置元数据文件src/main/resources/META-INF/spring-configuration-metadata.json:

内容:

{
  "properties": [
    {
      "name": "myapp.someprop",
      "type": "java.lang.String"
    },
    {
      "name": "myapp.someintprop",
      "type": "java.lang.Integer"
    }
  ]
}

选项1和2:

在构建系统(Maven/Gradle)的IntelliJ IDEA工具窗口中,单击刷新"按钮.

Options 1 and 2:

In the IntelliJ IDEA tool window of your build system (Maven/Gradle), click the "Refresh" button.

从菜单中选择Build > Rebuild Project.

如果仍然出现警告,则可以尝试重新启动IDE.选择File > Invalidate Caches / Restart并单击Invalidate and Restart.

If the warning still appears, you can try to restart the IDE. Select File > Invalidate Caches / Restart and click on Invalidate and Restart.

这篇关于Intellij IDEA抱怨无法解决弹簧启动属性,但它们可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆