如何为 Quarkus 扩展编写对象列表的配置
How to write the configuration of a list of objects for a Quarkus extension
我正在编写 Quarkus 扩展(内部使用),不知道如何正确编写配置部分。
我需要设置一个如下所示的配置,一个包含多个配置属性的对象列表。
some:
list-of-config:
- prop1: value1
prop2: value2
prop3: value3
- prop1: value4
prop2: value5
prop3: value6
所以我想使用 @ConfigGroup 和 List<>,如下例所示:
@ConfigRoot(name = "some", phase = ConfigPhase.BUILD_TIME)
public class MyConfig {
@ConfigItem(defaultValue = "true")
public boolean enabled;
public List<MyGroup> listOfConfig;
@ConfigGroup
public static class MyGroup {
@ConfigItem
public String prop1;
@ConfigItem
public String prop2;
@ConfigItem
public String prop3;
}
}
不幸的是,我在启动应用程序时遇到以下异常:
SRCFG00013: No Converter registered for class org....MyConfig$MyGroup
@ConfigGroup 在作为单个对象而不是作为列表加载时效果很好。我想这与配置组本身并没有真正的关系,因为我在不使用配置组但使用简单对象的情况下也遇到了这个错误。
有没有人尝试过使用对象列表作为 Quarkus 扩展的配置?官方文档缺少相关示例。
根据the documentation, any type not being listed or accepting a String parameter as constructor/valueOf/of cannot be used with List or Optional types, except Optional that can also be applied to a configuration group object. Unfortunately, Optional + config group is bugged as mentioned here
看来自定义对象不受支持,这回答了我的问题。
Quarkus 也在努力为扩展添加配置映射的使用,这应该可以解决问题并在未来的版本中添加对复杂类型的支持(目前是 2.1.0 在提出这个问题时)
我正在编写 Quarkus 扩展(内部使用),不知道如何正确编写配置部分。
我需要设置一个如下所示的配置,一个包含多个配置属性的对象列表。
some:
list-of-config:
- prop1: value1
prop2: value2
prop3: value3
- prop1: value4
prop2: value5
prop3: value6
所以我想使用 @ConfigGroup 和 List<>,如下例所示:
@ConfigRoot(name = "some", phase = ConfigPhase.BUILD_TIME)
public class MyConfig {
@ConfigItem(defaultValue = "true")
public boolean enabled;
public List<MyGroup> listOfConfig;
@ConfigGroup
public static class MyGroup {
@ConfigItem
public String prop1;
@ConfigItem
public String prop2;
@ConfigItem
public String prop3;
}
}
不幸的是,我在启动应用程序时遇到以下异常:
SRCFG00013: No Converter registered for class org....MyConfig$MyGroup
@ConfigGroup 在作为单个对象而不是作为列表加载时效果很好。我想这与配置组本身并没有真正的关系,因为我在不使用配置组但使用简单对象的情况下也遇到了这个错误。
有没有人尝试过使用对象列表作为 Quarkus 扩展的配置?官方文档缺少相关示例。
根据the documentation, any type not being listed or accepting a String parameter as constructor/valueOf/of cannot be used with List or Optional types, except Optional that can also be applied to a configuration group object. Unfortunately, Optional + config group is bugged as mentioned here
看来自定义对象不受支持,这回答了我的问题。 Quarkus 也在努力为扩展添加配置映射的使用,这应该可以解决问题并在未来的版本中添加对复杂类型的支持(目前是 2.1.0 在提出这个问题时)