【问题标题】:spring-configuration-metadata.json is not generated properly for multi-module projectspring-configuration-metadata.json 没有为多模块项目正确生成
【发布时间】:2022-01-23 23:38:28
【问题描述】:

我已经创建了多模块项目:

  • (pom)root
    • (罐子)libModule
    • (jar)appModule,在依赖项中有libModule

appModule pom 有依赖:

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

它还包含自己的@ConfigurationProperties 类:

    @ConfigurationProperties(prefix = "service.test")
    @Component
    @Data
    public class Conf {
        String prop;
    }

编译这个模块产生下一个正确的spring-configuration-metadata.json文件:

{
  "groups": [
    {
      "name": "service.test",
      "type": "org.test.app.Conf",
      "sourceType": "org.test.app.Conf"
    }
  ],
  "properties": [
    {
      "name": "service.test.prop",
      "type": "java.lang.String",
      "sourceType": "org.test.app.Conf"
    }
  ],
  "hints": []
}

我的 Idea IDE 成功地在 application.yml 中突出显示了我的这个属性

但我的libModule 中还有额外的@ConfigurationProperties 课程:

@ConfigurationProperties(prefix = "service.a")
@Setter
@Getter
public class ServiceAProperties {
    String url;
}

我尝试使用下一个代码将此类包含到 appModule 中:


@SpringBootApplication
@ConfigurationPropertiesScan(basePackageClasses = {
        ServiceAProperties.class
})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

并尝试了不同的方法将其包含到 json 中,但它没有出现在那里。只使用自己的模块Conf

如何包含来自其他模块的配置属性以生成正确的 json,包括两个模块的属性

如果需要一些额外的信息,请询问

【问题讨论】:

    标签: java spring-boot maven spring-boot-configuration configurationproperties


    【解决方案1】:

    好的。我的问题的答案是 - 我必须单独为 libModule 生成 json。应该以这种方式工作

    【讨论】:

      猜你喜欢
      • 2016-10-17
      • 2014-07-26
      • 2020-11-01
      • 2020-10-07
      • 2014-07-03
      • 2017-09-20
      • 2021-03-15
      • 1970-01-01
      • 2019-10-07
      相关资源
      最近更新 更多