ttulka
ttulka

Reputation: 10892

Can Spring Boot load case-sensitive Map keys from environment variables?

Setting an environment variable

MYAPP_MYMAP_CaseSensitive=foo

for a Map property of Spring Boot's (2.1.7.RELEASE) @ConfigurationProperties

@ConfigurationProperties(prefix = "myapp")
class MyProperties {
    private Map<String, String> myMap;
    // getters, setters...
}

loads the Map with keys in lowercase:

{casesensitive=foo}

So far I found a workaround using SPRING_APPLICATION_JSON:

SPRING_APPLICATION_JSON={"myapp.myMap":{"CaseSensitive":"foo"}}

Is there a correct way to set case-sensitive keys via environment variables?

Upvotes: 1

Views: 3199

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116211

No, it can't at the moment. This is something we'd like to improve in the future. That improvement is being tracked by this issue.

In the meantime, if you want to provide the configuration via an environment variable then using SPRING_APPLICATION_JSON is the recommended approach.

Upvotes: 1

Related Questions