-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
It all starts with an issue we have recently received in spring-cloud-kubernetes. I will try to simplify it as much as I can.
If I have an application.yaml
like this:
bean:
items:
- Item 1
- Item 2
- Item 3
- Item 4
- Item 5
---
spring:
config:
activate:
on-profile: dev
bean:
items:
- Item 1
- Item 6
- Item 7
and activate the dev
profile, bean.items
would be injected as [Item 1, Item 6, Item 7]
and that is of course correct.
We need to "replicate" the same thing in spring-cloud-kubernetes. There, we read a configmap for example and based on what's inside it, we would create the PropertySource
by hand.
The problem is, until now, we were using YamlPropertiesFactoryBean
, and this one would "override" properties for lists, because of this code:
protected Properties createProperties() {
Properties result = CollectionFactory.createStringAdaptingProperties();
this.process((properties, map) -> result.putAll(properties));
return result;
}
As such, we would end up with:
bean.items = [Item 1, Item 6, Item 7, Item 4, Item 5]
This happens because YamlPropertiesFactoryBean
does not know to override properly arrays and maps. I ended up creating our own class for this parsing, that is heavily based on YamlPropertiesFactoryBean
.
Ryan Baxter advised me to open an issue here to see if the real solution is in spring-boot and not us creating a custom parsing class.
Thank you.