简体   繁体   English

将自定义 application.yml 配置的子集加载到 Quarkus 中的地图时遇到问题

[英]Trouble loading a subset of custom application.yml configurations to a Map in Quarkus

I'm trying to use quarkus yaml extension as my main source for configs and I was trying to figure out what the best approach is for loading a map from the yaml file.我正在尝试使用 quarkus yaml 扩展作为我的主要配置来源,我试图找出从 yaml 文件加载地图的最佳方法是什么。

The application.yml : application.yml

quarkus:
  http:
    port: 8080
configuration:
  value:
    name1: test1
    name2: test2
    name3: test3

In the code I tried to inject the config value like this:在代码中,我尝试像这样注入配置值:

@ConfigProperty(name = "configuration.value")
Values value;

Where Values contains a custom Eclipse Microprofile Converter.其中 Values 包含自定义 Eclipse Microprofile Converter。 The converter looks like this:转换器看起来像这样:

public class ValueConverter implements Converter<Values> {
    @Override
    public Values convert(String value) {
        // Here there would be the actual code to convert to Map.
        return new Values(map);
    }
}

The problem is that String value comes empty, ie, it does not loading the stull below configuration.value:问题是 String 值是空的,即它不会加载 configuration.value 下面的 stull:

name1: test1
name2: test2
name3: test3

I've also tried annotating a class with @ConfigProperties(prefix = "configuration.value") and have a map inside but then it does not know how to map that to a Map as expected... Is there a way to create custom config properties converter?我也试过用@ConfigProperties(prefix = "configuration.value")注释一个类,里面有一个地图,但它不知道如何按预期将它映射到一个Map ......有没有办法创建自定义配置属性转换器?

Is this a Eclipse Microprofile issue?这是 Eclipse Microprofile 问题吗? Is this a bug?这是一个错误吗? Is this a feature request?这是功能请求吗? :) Or, is there another/better way of doing this? :) 或者,还有另一种/更好的方法吗?

Thanks for the help!谢谢您的帮助!

正如在此处的邮件列表中所回答的那样,Eclipse MicroProfile Config 不支持此功能,因此 Quarkus 不支持此功能。

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

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