【问题标题】:Can I configure IntelliJ to autocomplete spring boot properties in a git repo我可以将 IntelliJ 配置为在 git 存储库中自动完成 Spring Boot 属性吗
【发布时间】:2021-02-20 01:57:18
【问题描述】:

我有一个多模块 maven 项目(monorepo),其中有一个配置目录(由 spring 云配置服务器使用),我希望配置 IntelliJ 以使用 spring-boot-configuration 自动完成属性-处理器。

元数据(additional-spring-configuration-metadata.json)在微服务模块中正确生成,但我不知道如何配置 Intellij 以在具有外部化配置的目录中自动完成。这可能吗?

我尝试将普通配置目录设为 maven 模块,并添加 spring facet。

【问题讨论】:

    标签: spring-boot intellij-idea


    【解决方案1】:

    我找不到直接的方法,但这可以帮助你:
    https://intellij-support.jetbrains.com/hc/en-us/community/posts/360005091880-spring-cloud-config-documentation-and-completion
    这种方法是使用 spring 初始化程序制作一些虚拟应用程序并将其放在配置 repo 中。这样,intellij 将启用自动完成功能。您必须添加所有需要自动完成的模块。

    【讨论】:

      【解决方案2】:

      我想出的“微创方式”如下: 放一个[configurationName].iml文件,内容如下

      <?xml version="1.0" encoding="UTF-8"?>
      <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
        <component name="FacetManager">
          <facet type="Spring" name="Spring">
            <configuration />
          </facet>
        </component>
        <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
          <output url="file://$MODULE_DIR$/target/classes" />
          <output-test url="file://$MODULE_DIR$/target/test-classes" />
          <content url="file://$MODULE_DIR$">
            <excludeFolder url="file://$MODULE_DIR$/target" />
          </content>
          <orderEntry type="library" scope="PROVIDED" name="Maven: com.my.component:Major.Minor.Patch-SNAPSHOT" level="project" />
          ...
          <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.6.4" level="project" />
          <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.6.4" level="project" />
          <orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.6.4" level="project" />
          ...
          <orderEntry type="sourceFolder" forTests="false" />
        </component>
      </module>
      

      在 yml 文件的文件夹中。它是 IntelliJ 项目文件的精简版本,它应该引用项目中的所有依赖项,这些依赖项附带一个

      *spring-configuration-metadata.json
      

      可以使用文件搜索来识别它们

      spring-configuration-metadata.json
      

      在(非配置但代码)项目中选择在“所有地方”进行搜索。

      使用“在查找工具窗口中打开”(搜索对话框的最右角)方便将文件路径复制到剪贴板中进行编辑和提取。

      如果依赖关系发生变化,这种方法的缺点是过时,但由于 spring-configuration-metadata.json 不会经常更新并且不是关键任务,对我来说这是可以接受的。

      可能会出现“这些模块已从 Maven 结构中删除”弹出窗口,不要选择从项目中删除模块,这会破坏自动建议。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-10
        • 2016-08-22
        • 2019-04-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-21
        • 2018-11-14
        相关资源
        最近更新 更多