对象列表的配置

Configuration for list of objects

使用 Quarkus 配置系统,在我的应用程序中注入对象列表的最佳方式是什么?

就我而言,我想配置一个服务器列表及其类型。使用 yaml 配置:

app.servers
  - uri: host1
    type: type1
  - uri: host2
    type: type2

我只能找到基本类型数组的解决方案,但自定义类型是否可行 class?

由于问题是 quarkus begun supporting yaml configuration 文件,所以配置对象列表的最简单方法是通过 .yaml 配置文件

为此只需添加以下依赖项:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-config-yaml</artifactId>
</dependency>

如果您仍然需要将其作为 .properties 文件,那么我最终要做的(因为尚不支持 yaml)是实现 custom property converter.

我面临同样的问题,不幸的是,custom property converter 还不成熟,它会将 yaml 对象连接成一个字符串,如下所示:

uri=host1type=type1

您必须以编程方式拆分它并创建您的 dto。

这真的很丑...