Java 重新运行 Spring Boot Configuration Annotation Processor 来更新生成的元数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33483697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:42:49  来源:igfitidea点击:

Re-run Spring Boot Configuration Annotation Processor to update generated metadata

javaspringmavenintellij-idea

提问by Eric Francis

I've added:

我已经添加:

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

to my pom.xmlper intellij's request/warning.

pom.xml每次intellij的请求/警告。

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

现在我看到“重新运行 Spring Boot 配置注释处理器以更新生成的元数据”。

How do I do what intellijis asking me to do?

我如何做intellij要求我做的事情?

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

此链接B.2 使用注释处理器生成您自己的元数据没有说明。

采纳答案by Patrick Herrera

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

遵循这些说明对我有用: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.

关键似乎是在添加所需的依赖项后或在进行任何属性更改后重建项目。这样做并返回 YAML 文件后,我的所有属性现在都链接到配置类。

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.

您可能还需要单击 Maven 窗格中的“重新导入所有 Maven 项目”按钮以获取 .yaml 文件视图以识别返回到相应 Java 类的链接。

回答by Deathtiny

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

我遇到过同样的问题。问题是 Spring Boot 注释处理器spring-configuration-metadata.json在您的/target/classes/META-INF文件夹中生成文件。

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.

如果您像我一样在 IntelliJ 中碰巧忽略了这个文件夹(因为到底是什么,谁在乎类文件?),该文件将不会被您的 IDE 编入索引。因此,没有完成,以及烦人的消息。

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

只需target从忽略文件/文件夹列表中删除,位于Settings > Editor > File Types > Ignore files and folders.

回答by Lorenzo Polidori

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

没有一个答案对我有用。如果您只想禁用该消息,请转到 Intellij Preferences -> Editor -> General -> Appearance,取消选中“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.

但是,您也可以接受该消息,如果它不会打扰您太多,因此请确保您不会错过您可能感兴趣的任何其他 Spring Boot 元数据消息。

回答by Jason Turan

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.

这些选项都不适合我。我发现注释处理器的自动检测非常不稳定。我最终在 pom.xml 文件中创建了一个插件部分,该部分显式设置了用于项目的注释处理器。这样做的好处是您不需要依赖任何 IDE 设置。

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

回答by Brandon S

You can enable annotation processors in IntelliJ via the following:

您可以通过以下方式在 IntelliJ 中启用注释处理器:

  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
  1. 点击文件
  2. 点击设置
  3. 在左上角的小搜索框中,搜索“Annotation Processors”
  4. 选中“启用注释处理”
  5. 单击确定

回答by timomeinen

  1. Include a dependency on spring-boot-configuration-processor
  2. Click "Reimport All Maven Projects" in the Maven pane of IDEA
  3. Rebuild project
  1. 包含对 spring-boot-configuration-processor 的依赖
  2. 在IDEA的Maven面板中点击“Reimport All Maven Projects”
  3. 重建项目