【问题标题】:Configuration for MicroProfile: how inject list of custom objectMicroProfile 的配置:如何注入自定义对象列表
【发布时间】:2021-03-13 14:51:48
【问题描述】:

我正在尝试在 quarkus 中注入对象列表,但收到错误消息“没有为类 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;
}

我做错了什么?

【问题讨论】:

    标签: java quarkus eclipse-microprofile-config


    【解决方案1】:

    您需要提供一个 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

    【讨论】:

    • 它可以工作,但是当我为本地运行程序打包时它不起作用。我收到此错误“Cannot create property=externals-api-list for JavaBean=ExternalApiParams(externals-api-list=null)”。你有什么建议吗?
    • 你能提供更多的上下文吗?
    • 我在我的 quarkus 应用程序中以 jar 模式使用了这种方法,它可以工作。当我尝试以本机模式打包我的应用程序时,它不起作用。也许@ConfigMapping 会导致 quarkus 在本机模式下出现问题?
    • 它引起了问题,那么它就是一个错误。你能提供给我一个复制器吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-09-28
    • 2019-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    相关资源
    最近更新 更多