As
we have seen above
, any YAML content is
ultimately transformed to properties. That process may be counter intuitive when
overriding “list” properties via a profile.
For example, assume a
MyPojo
object with
name
and
description
attributes
that are
null
by default. Let’s expose a list of
MyPojo
from
FooProperties
:
@ConfigurationProperties("foo")
public class FooProperties {
private final List<MyPojo> list = new ArrayList<>();
public List<MyPojo> getList() {
return this.list;
}
Consider the following configuration:
foo:
list:
- name: my name
description: my description
spring:
profiles: dev
foo:
list:
- name: my another name
If the
dev
profile isn’t active,
FooProperties.list
will contain one
MyPojo
entry
as defined above. If the
dev
profile is enabled however, the
list
will
still
only contain one entry (with name “my another name” and description
null
). This
configuration
will not
add a second
MyPojo
instance to the list, and it won’t merge
the items.
When a collection is specified in multiple profiles, the one with highest priority is
used (and only that one):
foo:
list:
- name: my name
description: my description
- name: another name
description: another description
spring:
profiles: dev
foo:
list:
- name: my another name
In the example above, considering that the
dev
profile is active,
FooProperties.list
will contain
one
MyPojo
entry (with name “my another name” and description
null
).