未注入 Quarkus YAML 配置

Quarkus YAML config is not injected

正在尝试将 YAML 用于我的 Quarkus 配置,看起来将配置值注入 @ConfigProperty 时出现问题。

如何重现

  1. 创建示例项目
mvn io.quarkus:quarkus-maven-plugin:1.12.2.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=getting-started \
    -DclassName="org.acme.getting.started.GreetingResource" \
    -Dpath="/hello"
cd getting-started
  1. 更新GreetingResource
@Path("/hello")
public class GreetingResource {
    @ConfigProperty(name = "org.acme.getting.started.value")
    String value;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "value " + value;
    }
}
  1. 添加application.properties
org.acme.getting.started.value=8
  1. 启动应用程序并检查端点。有效
./mvnw compile quarkus:dev

curl http://localhost:8080/hello
value 8
  1. 添加 YAML 配置支持
./mvnw quarkus:add-extension -Dextensions="config-yaml"
  1. 删除 application.properties 并创建 application.yaml
"org.acme.getting.started.value": "8"
  1. 启动应用程序
mvn clean
./mvnw compile quarkus:dev
2021-03-18 01:30:32,890 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): javax.enterprise.inject.spi.DeploymentException: No config value of type [java.lang.String] exists for: org.acme.getting.started.value
        at io.quarkus.arc.runtime.ConfigRecorder.validateConfigProperties(ConfigRecorder.java:39)

我检查了两个 quarkus config docs and smallrye docs,没有发现那里对 YAML 配置映射有任何特殊要求。还尝试了 application.yaml 的不同格式:带引号的名称、不带引号的名称、单行、多行。 None 的工作人员。

有什么我遗漏的吗?还是我应该报告错误?

UPD 我尝试将其分解为多行 YAML(以某种方式我希望在我的真实应用程序中使用它)

org:
  acme:
    getting.started:
        value: 8

尝试了引用和不引用,none 成功了。为了使其工作,您需要将每个新的关键部分放在新的一行中,请参阅@Roberto Cortez answer

要使 YAML 配置正常工作,需要定义如下:

org:
  acme:
    getting:
      started:
        value: 8

这与https://github.com/quarkusio/quarkus/issues/11744

有关