@ConfigurationProperties Spring Boot Configuration Annotation Processor not found in classpath

Spring BootIntellij Idea

Spring Boot Problem Overview


I try to make completion for custom properties in Spring Boot.

I tried to create a simple project via IntelliJ IDEA 2016.3:

  1. Created a new Gradle project with Spring Boot Initializer (I haven't checked anything at all).
  2. Created a new class Properties.

When I annotated it with @ConfigurationProperties, the next notification has appeared: notification

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).

Spring Boot Solutions


Solution 1 - Spring Boot

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.

Solution 2 - Spring Boot

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.

Solution 3 - Spring Boot

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>2.0.4.RELEASE</version>
        </path>
      </annotationProcessorPaths>
    </configuration>
  </plugin>
</plugins>
</build>

Solution 4 - Spring Boot

It happens to me for two reasons in IDEA:

  1. Double check if your setting is picked (enabled) in IDEA: Preferences->Annotation Processors->Enable annotation processing.
  2. After update your Idea, check your plugins and update them. It happens that plugins become incompatible with your new IDEA version, so just click to update them.

Solution 5 - Spring Boot

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

Solution 6 - Spring Boot

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).

Solution 7 - Spring Boot

In maven project helps adding dependency spring-boot-configuration-processor and marking main class with @EnableConfigurationProperties(AppProperties.class).

Maybe somebody helps.

Solution 8 - Spring Boot

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" > }

Solution 9 - Spring Boot

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")
}

Solution 10 - Spring Boot

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);
    }

}

Solution 11 - Spring Boot

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') 

Solution 12 - Spring Boot

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)

Solution 13 - Spring Boot

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'
    // ...
}

Solution 14 - Spring Boot

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:

https://github.com/spring-guides/tut-spring-boot-kotlin/blob/master/README.adoc#configuration-properties

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFeecoView Question on Stackoverflow
Solution 1 - Spring BootIcexView Answer on Stackoverflow
Solution 2 - Spring BootnaXa stands with UkraineView Answer on Stackoverflow
Solution 3 - Spring BootanandbibekView Answer on Stackoverflow
Solution 4 - Spring BootVictor SchurenkoView Answer on Stackoverflow
Solution 5 - Spring BootJeffersonSousaView Answer on Stackoverflow
Solution 6 - Spring BootFeecoView Answer on Stackoverflow
Solution 7 - Spring BootOleg PavlyukovView Answer on Stackoverflow
Solution 8 - Spring BootAR1View Answer on Stackoverflow
Solution 9 - Spring BootnaXa stands with UkraineView Answer on Stackoverflow
Solution 10 - Spring BootMafeiView Answer on Stackoverflow
Solution 11 - Spring BootvargapetiView Answer on Stackoverflow
Solution 12 - Spring BootDirk HoffmannView Answer on Stackoverflow
Solution 13 - Spring BootnaXa stands with UkraineView Answer on Stackoverflow
Solution 14 - Spring BootPeterView Answer on Stackoverflow