esin88
esin88

Reputation: 3199

Quarkus YAML config is not injected

Was trying to use YAML for my configs with Quarkus, and it looks like there's an issue with injecting config values to @ConfigProperty.

How to reproduce

  1. Create sample project
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. Update 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. Add application.properties
org.acme.getting.started.value=8
  1. Start the application and check the endpoint. It works
./mvnw compile quarkus:dev

curl http://localhost:8080/hello
value 8
  1. Add YAML config support
./mvnw quarkus:add-extension -Dextensions="config-yaml"
  1. Delete application.properties and create application.yaml.
"org.acme.getting.started.value": "8"
  1. Start the app
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)

I checked both quarkus config docs and smallrye docs, didn't find any special requirements for YAML config mapping there. Also tried different formats for application.yaml: quoted names, unquoted names, single-line, multi-line. None of those worked.

Is there anything I'm missing? Or should I report a bug?

UPD I tried breaking it down to multiline YAML like (in a way I would like to have it in my real app)

org:
  acme:
    getting.started:
        value: 8

tried both quoted and unquoted, none of those worked. In order to make it work, you need to put each new key part to a new line, see @Roberto Cortez answer

Upvotes: 0

Views: 1757

Answers (1)

Roberto Cortez
Roberto Cortez

Reputation: 1163

For the YAML configuration to work it needs to defined like:

org:
  acme:
    getting:
      started:
        value: 8

This is related with https://github.com/quarkusio/quarkus/issues/11744

Upvotes: 2

Related Questions