I've got an application.yml that looks something like this:
root:
mapkey:
name-with-dashes:
vara: some value 1
varb: 1
different-name-with-dashes:
vara: some value 2
varb: 2
I am using the @ConfigurationProperties annotation to inject a config POJO that matches this structure. It looks basically like this (removed constructors etc. for readability, but just know that it works):
@Configuration
@ConfigurationProperties("root")
public class ParentConfig {
private Map<String, ChildConfig> mapkey;
}
public class ChildConfig {
private String vara;
private Integer varb;
}
Locally when testing this, I have no issues and the injection works fine.
However, I run into an issue when trying to deploy and override these fields with system variables. From the Springboot Documentation, it says that the system properties should be created by converting the periods to underscores, removing the dashes, and converting to uppercase. In my case then I end up with variables like this:
ROOT_MAPKEY_NAMEWITHDASHES_VARA: deployment value 1
ROOT_MAPKEY_NAMEWITHDASHES_VARB: 6
ROOT_MAPKEY_DIFFERENTNAMEWITHDASHES_VARA: deployment value 2
ROOT_MAPKEY_DIFFERENTNAMEWITHDASHES_VARB: 12
However, when I run the application with these variables and inspect the ParentConfig object, the map looks like this:
{
mapkey: {
name-with-dashes: {
vara: deployment value 1
varb: 6
},
namewithdashes: {
vara: deployment value 1
varb: 6
},
different-name-with-dashes: {
vara: deployment value 2
varb: 12
},
differentnamewithdashes: {
vara: deployment value 2
varb: 12
}
}
}
It's duplicating the properties with and without dashes and I have no idea why. And not just that, but all of the values have the deployment values, not the application.yml values. Very confusing.