179

I've added:

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

to my pom.xml per intellij's request/warning.

Now I'm seeing "Re-run Spring Boot Configuration Annotation Processor to update generated metadata".

How do I do what intellij is asking me to do?

This link, B.2 Generating your own meta-data using the annotation processor, does not have instructions.

Eric Francis
  • 23,039
  • 31
  • 88
  • 122

13 Answers13

96

Following these instructions worked for me: http://www.mdoninger.de/2015/05/16/completion-for-custom-properties-in-spring-boot.html

That message about having to Re-run the Annotation Processor is a bit confusing as it appears it stays there all the time even if nothing has changed.

The key seems to be rebuilding the project after adding the required dependency, or after making any property changes. After doing that and going back to the YAML file, all my properties were now linked to the configuration classes.

You may need to click the 'Reimport All Maven Projects' button in the Maven pane as well to get the .yaml file view to recognise the links back to the corresponding Java class.

Patrick Herrera
  • 3,120
  • 26
  • 21
  • So there's no way to get rid of the message? – OrangeDog Dec 16 '15 at 11:38
  • 1
    @OrangeDog Not that I can find. I've learnt to ignore it but you could always lodge a feature request with JetBrains. You would imagine that they could be a bit smarter about this and only display it if they know the class file or the configuration file has actually changed – Patrick Herrera Dec 18 '15 at 00:08
  • 1
    The error message still stays there after rebuilding the project. – Kent Bull Jan 05 '17 at 17:10
  • 9
    "The key seems to be rebuilding the project" helped me. The message is still here, but at least auto-completion of my custom properties in `application.properties` file started to work. – Ruslan Stelmachenko Oct 21 '17 at 16:12
  • 1
    I use IDEA 2018.3 and have a link "Hide notification" after the text message. Looks as if JetBrains made the info closeable :-) – Marcus K. Mar 01 '19 at 12:24
22

None of these options worked for me. I've found that the auto detection of annotation processors to be pretty flaky. I ended up creating a plugin section in the pom.xml file that explicitly sets the annotation processors that are used for the project. The advantage of this is that you don't need to rely on any IDE settings.

<plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessors>
                    <annotationProcessor>org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor</annotationProcessor>
                    <annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
                    <annotationProcessor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</annotationProcessor>
                </annotationProcessors>
            </configuration>
        </plugin>
Jason Turan
  • 1,302
  • 12
  • 20
  • 8
    This one worked for me. I used `annotationProccessorPaths` instead of defining individual classes. `org.springframework.bootspring-boot-configuration-processor${parent.version}...` – Fırat Küçük Jul 18 '19 at 07:56
  • For me it worked without the maven-compiler-plugin, I only needed the spring-boot-maven-plugin (version 2.5.5). – Jasper Citi Oct 05 '21 at 03:50
20

You can enable annotation processors in IntelliJ via the following:

  1. Click on File
  2. Click on Settings
  3. In the little search box in the upper-left hand corner, search for "Annotation Processors"
  4. Check "Enable annotation processing"
  5. Click OK
Brandon S
  • 1,543
  • 1
  • 13
  • 13
16

None of the answers worked for me. If you just want to disable the message, go to Intellij Preferences -> Editor -> General -> Appearance, uncheck "Show Spring Boot metadata panel".

However, you can also live with that message, if it does not bother you too much, so to make sure you don't miss any other Spring Boot metadata messages you may be interested in.

Lorenzo Polidori
  • 10,332
  • 10
  • 51
  • 60
  • 8
    The check box is with IDEA 2017.2 under Preferences -> Languages & Frameworks -> Spring -> Spring Boot – oleh Jul 02 '17 at 14:01
13

I had the same issue. The problem is that the Spring Boot annotation processor generates the spring-configuration-metadata.json file inside your /target/classes/META-INF folder.

If you happen to have ignored this folder in IntelliJ like me (because what the heck, who cares about classes files?), the file won't be indexed by your IDE. Therefore, no completion, and the annoying message.

Just remove target from the ignore files/folders list, located in Settings > Editor > File Types > Ignore files and folders.

Deathtiny
  • 728
  • 3
  • 8
  • 14
  • 4
    I don't see `target` in my ignored files. It is in my `.gitignore` though. – Eric Francis Dec 21 '15 at 22:11
  • `target/` is excluded in my case and things are working fine. – Amr Mostafa Mar 24 '16 at 12:37
  • 3
    It will be used whether or not target is excluded or not (I'm the developer responsible for this feature). Please file a bug report if you can reproduce this wrong behavior. – Yann Cébron Sep 30 '16 at 08:33
  • 1
    so which version of IntelliJ behaves properly? – Marx Oct 18 '16 at 11:24
  • IntelliJ 14.1.7 here, not working either, tried all the answers here already – cahen Jan 24 '17 at 12:05
  • 2
    @YannCébron same here, with gradle. The file gets created in ./build/classes/java/main/META-INF/spring-configuration-metadata.json, but IntelliJ doesn't take it into account. If I manually move the json file to src/main/resources/META-INF it works (the configs are no longer yellowed) – Costi Muraru May 30 '18 at 13:04
11

For me, other answers didn't work. I had to go to open Files and do Invalidate caches and restart on Intellij. After that, everything worked fine again.

Sepehr GH
  • 1,297
  • 1
  • 17
  • 39
5

Having included a dependency on spring-boot-configuration-processor in build.gradle:

annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:2.4.1"

the only thing that worked for me, besides invalidating caches of IntelliJ and restarting, is

  1. Refresh button in side panel Reload All Gradle Projects
  2. Gradle task Clean
  3. Gradle task Build
fachexot
  • 491
  • 1
  • 8
  • 24
4
  1. Include a dependency on spring-boot-configuration-processor
  2. Click "Reimport All Maven Projects" in the Maven pane of IDEA
  3. Rebuild project
timomeinen
  • 3,101
  • 3
  • 33
  • 46
4

I just needed

@EnableConfigurationProperties({MY_PROPS_CLASS.class})

in Main Application class and it helped me to resolve this issue

the one
  • 437
  • 4
  • 7
3

I had a similar issue using Gradle and Kotlin. You should modify the build.gradle.kts file to include the following:

//build.gradle.kts
plugins {
  // ...
  kotlin("kapt") version "1.5.31"
}


dependencies {
  // ...

  kapt("org.springframework.boot:spring-boot-configuration-processor")
}

Then, to generate the annotations:

./gradlew kaptKotlin

References: https://spring.io/guides/tutorials/spring-boot-kotlin/#_configuration_properties

Neuron
  • 5,141
  • 5
  • 38
  • 59
2

None of the above worked in my case, but brought me close. In the end explicitly defining all required annotationProcessors in the maven-compiler-plugin solved it for me. In my case this was: Spring-Boot + Lombok + MapStruct

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
      <annotationProcessorPaths>
        <annotationProcessorPath>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>${lombok.version}</version>
        </annotationProcessorPath>
        <annotationProcessorPath>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>${mapstruct.version}</version>
        </annotationProcessorPath>
        <annotationProcessorPath>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-configuration-processor</artifactId>
          <version>${spring-boot-configuration-processor.version}</version>
        </annotationProcessorPath>
      </annotationProcessorPaths>
    </configuration>
  </plugin>

Before that I always got some warnings in the Class + in the application.properties some properties were marked as "unusued", even when they were defined in a class with @ConfigurationProperties

Mario B
  • 2,102
  • 2
  • 29
  • 41
  • The documentation says: "If you are using Lombok in your project, you need to make sure that its annotation processor runs before spring-boot-configuration-processor". https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#appendix.configuration-metadata.annotation-processor.configuring – Rod Lima Jul 05 '23 at 15:18
  • @RodLima: It does seem to work just fine for me, even with the wrong order. Still, I updated my answer to reflect this, certainly better to stick with what the official documentation says Thank you! – Mario B Jul 06 '23 at 07:41
0

I had the same problem. In my case I was missing the spring-boot-maven-plugin.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

as well as the @Data Lombok annotation

@Configuration
@ConfigurationProperties("logging.web")
@Data
public class LoggingWebConfiguration {
// ...
}

Obviously you can also just create the getter/setters yourself.

Then you must also remember to re-import and re-compile your project.

Jasper Citi
  • 1,673
  • 1
  • 23
  • 31
0

In the maven panel of Idea, clean and compile in the maven lifecycle worked for me.