sebastiandaschner blog

Map complex configuration structures with Quarkus

#quarkus saturday, july 17, 2021

In Quarkus you can easily inject configured values using @ConfigProperty. There’s also a way to inject nested and collection values using configuration objects. In the following video, I’ll show how:



In my example, we’re going to map the following nested configuration values into a Java type:

Before Quarkus version two there was a way to use the @ConfigProperties annotation, whereas now the recommended way is to use @ConfigMapping:

@ConfigMapping(prefix = "complex")
public interface ComplexConfiguration {

    String coffee();
    List<String> list();

    SomeOther someOther();

    interface SomeOther {
        String coffee();
        List<String> list();

This ComplexConfiguration type can be injected as a bean using @Inject in our code.

It’s also possible, and sometimes helpful, to use a hierarchical format, such as YAML, to configure the values. The same example can be realized with a application.yaml config file, instead of

  coffee: coffee
  - 123
  - 234
  - 456
    coffee: abc123
    - abc123
    - abc234
    - abc345

For this, you’ll need to add the quarkus-config-yaml dependency.

As always, you can find the code on GitHub.

For more information, have a look at the config mapping documentation.

And, if you want to learn more about modern development with Quarkus, have a look at my upcoming Quarkus workshops.


Do you want to learn more about modern development with Quarkus? Then have a look at my upcoming online workshops in October.