Spring Cloud Config Client-具有相同前缀的聚合配置



我通过Spring Boot Microservice应用程序中的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<>();
.
.

现在,我正在尝试加载更多具有与上面提到的结构完全相同的配置(文件(,但我希望将它们聚合到上面"list"对象下列出的同一类中。

我该如何实现?

请参阅以下链接的第2.8.7节

https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-具有外部配置

它清楚地说明了(尽管用于在不同的配置文件中加载属性(-当在多个位置配置列表时,通过替换整个列表来进行覆盖。

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

这个特殊的用例不受Spring引导的支持,请参考以下线程了解更多细节

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

最新更新