简体   繁体   English

MicroProfile 的配置:如何注入自定义 object 列表

[英]Configuration for MicroProfile: how inject list of custom object

i'm trying to inject a list of object in quarkus but I receive an error "No Converter registered for class ExternalApiParam".我正在尝试在 quarkus 中注入 object 列表,但收到错误消息“没有为 class ExternalApiParam 注册转换器”。

My yaml is:我的 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

My config class is:我的配置 class 是:

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

    List<ExternalApiParam> externalApiList;
}

What do I wrong?我错了什么?

You need to provide a Config Converter class that can read the configuration value and convert it to your object.您需要提供一个配置转换器 class 可以读取配置值并将其转换为您的 object。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM