Reputation: 5236
I try to make completion for custom properties in Spring Boot.
I tried to create a simple project via IntelliJ IDEA 2016.3:
Properties
.When I annotated it with @ConfigurationProperties
, the next notification has appeared:
The documentation said that I should add the following to my project:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
compileJava.dependsOn(processResources)
After that, I tried to rebuild the project and enable annotation processors in settings but the notification hasn't gone. Completion doesn't work too (I created a string my
).
Upvotes: 140
Views: 160918
Reputation: 157
For this issue, we need to use annotations on the top of the main class of the project and mention this annotation to enable the
@EnableConfigurationProperties(AccountsContactInfoDto.class)
Upvotes: 0
Reputation: 61
This error can be resolved by adding this annotation in your mainApplicaitonClass
@EnableConfigurationProperties({class name}.class)
Upvotes: 0
Reputation: 2604
For those who are using maven, Intellij was still not happy with the addition of dependency. Seems like adding annotationProcessorPaths
via maven-compiler-plugin
finally tamed the beast.
Make sure the version
matches your spring dependencies. I suspect it would be already present in your effective POM.
Reason: I was using a custom parent-pom which had a mapstruct annotation processor set in annotationProcessorPaths
and that actually triggered IntelliJ to ask for all other annotation processors to be specified manually as well.
<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>${project.parent.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Upvotes: 45
Reputation: 1602
Spring's website has a tutorial that contains a great explanation how to make it work. Just follow the steps under "Configuration properties" section below.
It has one of the steps which none of other answers mentioned here:
run ./gradlew kaptKotlin
manually.
As of Mar 2021, IDEA will still show the warning on top of the Kotlin properties class, but the properties will be recognized and work. You'll be able to navigate from .properties
file to the Kotlin properties class, but not the other way around.
https://spring.io/guides/tutorials/spring-boot-kotlin/ scroll down to "Configuration properties" part.
Or the same page on GitHub:
Upvotes: 0
Reputation: 3819
You have to mention in the main class the class you want to use @ConfigurationProperties annotation like below.
@EnableConfigurationProperties(AppProperties.class)
The Property Configuration class with @ConfigurationProperties will be like this
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class AppProperties {
String name;
String id;
}
The Main class will be like this
import com.auth2.demo.config.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Upvotes: 5
Reputation: 541
For those using Maven or Gradle, just add the dependency on spring-boot-configuration-processor.
Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
Gradle 4.5 and earlier
dependencies {
compileOnly "org.springframework.boot:spring-boot-configuration-processor"
}
Gradle 4.6 and later
dependencies {
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
}
For more information: "Generating Your Own Metadata by Using the Annotation Processor" https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-configuration-metadata.html#configuration-metadata-annotation-processor
Upvotes: 27
Reputation: 37993
According to the Spring Boot docs, the correct configuration for Gradle 4.5 and earlier is
dependencies {
compileOnly group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ...
}
Upvotes: 0
Reputation: 37993
According to the Spring Boot docs, the correct configuration since Gradle 4.6 is
dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ...
}
IntelliJ IDEA supports annotationProcessor
scope since build 193.3382 (2019.3). Don't forget to enable annotation processing in IntelliJ IDEA settings.
Upvotes: 46
Reputation: 37993
For Kotlin projects, the working configuration since Gradle 4.6 is using annotation processor
apply plugin: "kotlin-kapt"
dependencies {
kapt("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")
compileOnly("org.springframework.boot:spring-boot-configuration-processor:$springBootVersion")
}
Upvotes: 7
Reputation: 161
In maven project helps adding dependency spring-boot-configuration-processor and marking main class with @EnableConfigurationProperties(AppProperties.class).
Maybe somebody helps.
Upvotes: 10
Reputation: 201
It happens to me for two reasons in IDEA:
Upvotes: 20
Reputation: 5023
In version 2018.3 of IntelliJ, I solved this problem (as per this documentation) in the following way:
With Gradle 4.5 and earlier, the dependency should be declared in the compileOnly configuration, as shown in the following example:
dependencies { compileOnly "org.springframework.boot:spring-boot-configuration-processor" }
With Gradle 4.6 and later, the dependency should be declared in the annotationProcessor configuration, as shown in the following example:
dependencies { annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" }
Upvotes: 7
Reputation: 301
I had the same problem with IntelliJ version 2018.1.2. I also had to define the actual version of spring-boot-configuration-processor in order to get it worked:
compile('org.springframework.boot:spring-boot-configuration-processor:2.0.1.RELEASE')
Upvotes: 2
Reputation: 1573
following works for me:
buildscript {
repositories {
jcenter()
maven { url 'https://repo.jenkins-ci.org/public/' }
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath "io.spring.gradle:propdeps-plugin:0.0.9.RELEASE"
}
}
...
apply plugin: 'propdeps'
apply plugin: 'propdeps-eclipse'
apply plugin: 'propdeps-idea'
...
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:2.0.0.RELEASE'
}
}
...
dependencies {
compile "org.springframework.boot:spring-boot-starter"
compile "org.springframework.boot:spring-boot-starter-actuator"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" // for @ConfigurationProperties, make sure compileJava.dependsOn(processResources)
...
}
compileJava.dependsOn(processResources)
Upvotes: 0
Reputation: 796
I had the same problem. I use idea 2017.2 and gradle 4.1, and some blog said you should add:
dependencies {
optional "org.springframework.boot:spring-boot-configuration-processor"
}
But I changed it to this:
dependencies {
compile "org.springframework.boot:spring-boot-configuration-processor"
}
And the warning is gone.
Upvotes: 78
Reputation: 5236
I forgot to add propdeps-plugin. However, I remember that it didn't work for me even with the plugin on 2016.3, So as @CrazyCoder mentioned, try to downgrade Gradle or download the new 2017.1 version (details).
Also you may receive Re-run Spring Boot Configuration Annotation Processor to update generated metadata
when you will solve this issue. For this, click Refresh all Gradle projects
(in Gradle side menu).
Upvotes: 11