Intellij IDEA complains cannot resolve spring boot properties but they work fine

我的未来我决定 提交于 2019-12-03 00:56:56

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

Option 1:

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>

Gradle:

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

Option 2:

Create the configuration metadata file yourself src/main/resources/META-INF/spring-configuration-metadata.json:

Content:

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

Options 1 and 2:

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

Select Build > Rebuild Project from the menu.

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

marcusti

You turn off the inspection in the IntelliJ Settings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!