Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

Can not resolve configuration property '...

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?

like image 233
Stoopkid Avatar asked Feb 23 '18 18:02

Stoopkid


People also ask

Does IntelliJ IDEA support Spring Boot?

IntelliJ IDEA creates and executes the Spring Boot run configuration.

How do I enable Spring framework in IntelliJ?

Enable Spring support in IntelliJ IDEAPress Ctrl+Alt+S to open the IDE settings and select Plugins. Open the Installed tab, search for Spring and make sure that the checkboxes next to all relevant plugins are selected.

What is @configuration Spring Boot?

One of the most important annotations in spring is @Configuration annotation which indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application. This annotation is part of the spring core framework.


1 Answers

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.

like image 102
Igor Akkerman Avatar answered Sep 18 '22 15:09

Igor Akkerman