gpt4 book ai didi

java - MicroProfile : how inject list of custom object 的配置

转载 作者:行者123 更新时间:2023-12-05 06:56:35 25 4
gpt4 key购买 nike

我正在尝试在 quarkus 中注入(inject)对象列表,但收到错误“没有为类 ExternalApiParam 注册转换器”。

我的 yaml 是:

custom:
external-api-list:
- name: example-1
uri: https://run.mocky.io/v3/55402172-82c3
- name: example-2
uri: https://run.mocky.io/v3/13417375-a19c

我的配置类是:

@ConfigProperties(prefix = "custom")
@Data
public class ExternalApiConfigProperties {

List<ExternalApiParam> externalApiList;
}

我做错了什么?

最佳答案

您需要提供一个 Config Converter 类,它可以读取配置值并将其转换为您的对象。

请在此处查看示例: https://github.com/smallrye/smallrye-config/blob/master/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java#L141-L153

以及如何使用转换器: https://quarkus.io/guides/config#custom-configuration-converters

关于java - MicroProfile : how inject list of custom object 的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65094647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com