Skip to content

Commit

Permalink
Add documentation about using list of objects in @ConfigProperties
Browse files Browse the repository at this point in the history
Related to: quarkusio#14006
  • Loading branch information
geoand committed Jan 7, 2021
1 parent 28d77a5 commit 53ebff7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/src/main/asciidoc/config-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,51 @@ public class SomeBean {
<1> At this injection point `greetingConfiguration` will use the `greeting` prefix since that is what has been defined on `@ConfigProperties`.
<2> At this injection point `otherConfiguration` will use the `other` prefix from `@ConfigPrefix` instead of the `greeting` prefix. Notice that in this case `@Inject` is not required.

=== Using a list of objects

In certain cases it might be necessary to support complex configuration structures that utilize a list of objects as shown in the following example:

`ComplexConfiguration.java`
[source,java]
----
@ConfigProperties(prefix = "complex")
public class ComplexConfiguration {
public String name;
public String user;
public String password;
public List<Nested> inputs;
public List<Nested> outputs;
public static class Nested {
public String user;
public String password;
}
}
----

`@ConfigProperties` can only support such use cases when the `quarkus-config-yaml` extension is present. A corresponding example YAML configuration could be:

`application.yaml`
[source,yaml]
----
complex:
name: defaultName
user: defaultUser
password: defaultPassword
inputs:
- user: user
password: secret
- user: otheruser
password: secret2
outputs:
- user: someuser
password: asecret
- user: someotheruser
password: anothersecret
----

WARNING: A limitation of such configuration is that the types used as the generic types of the lists need to be classes and not interfaces.

[[configuration_profiles]]
== Configuration Profiles

Expand Down

0 comments on commit 53ebff7

Please sign in to comment.