【问题标题】:Spring Cloud Config Client - Aggregate Config with the same prefixSpring Cloud Config Client - 具有相同前缀的聚合配置
【发布时间】:2020-07-27 08:57:02
【问题描述】:

我在 Spring Boot 微服务应用程序中通过 Spring Cloud Config Server 加载了以下配置:

{
  "routes": {
    "list": [
      {
        "a": "a1",
        "b": "b1"
      },
      {
        "a": "a2",
        "b": "b2"
      }
    ]
  }
}

在我的客户端 Spring Boot 应用程序中,我有以下将配置映射到对象:

@Component
@ConfigurationProperties( prefix = "routes" )
public class MyClass
{
    private List<MyDest> list = new ArrayList<>();
.
.

现在我正在尝试加载更多具有上述完全相同结构的配置(文件),但是我想将它们聚合到上面列出的“列表”对象下的同一个类中。

我该如何实现?

【问题讨论】:

    标签: spring-boot spring-cloud-config


    【解决方案1】:

    请参阅以下链接中的第 2.8.7 节

    https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config

    它明确指出(尽管用于跨不同配置文件加载属性)- 当列表配置在多个位置时,覆盖通过替换整个列表来工作。

    我相信跨多个文件定义的属性也是如此,尽管它们保存在同一配置文件下。

    Spring boot 不支持此特定用例,请参阅以下主题以了解更多详细信息

    https://github.com/spring-projects/spring-boot/issues/6670

    https://github.com/spring-projects/spring-boot/issues/9137

    https://github.com/spring-projects/spring-boot/issues/16394

    【讨论】:

      猜你喜欢
      • 2020-06-03
      • 2019-01-07
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 2018-05-30
      • 2018-01-27
      • 2022-12-04
      • 1970-01-01
      相关资源
      最近更新 更多