Spring-boot: Inconsistent binding from environment varaibles to maps

Created on 14 Apr 2017  路  6Comments  路  Source: spring-projects/spring-boot

I've noticed an inconsistency in properties binding from an ENV variable and property defined in application.properties

Consider following example:

@ConfigurationProperties("com.test")
public class Props {
    private Map<String, Map<String, String>> property;
}

application.properties <- binding works correctly

com.test.property.foo.bar=value

Environment variable <- binding fails

export COM_TEST_PROPERTY_CCC_DDD=VALUE

I would expect that the same binding behavior for an externalized configuration.
Any idea how to resolve this issue using Spring Boot 1.5.2?


I am using Spring Boot 1.5.2, Linux Mint 18.1, Java 8 ("1.8.0_121")
Demo application available: https://github.com/peterjurkovic/spring-boot-binding-demo

bug

All 6 comments

Looks like the same issue I reported as https://jira.spring.io/browse/SPR-15451

does this work? export SPRING_APPLICATION_JSON='{"com.test": {"property":{"foo": {"bar" : "value"} } } }'

The JSON is probably your only option with 1.5.x. We're reworking binding in Boot 2.0 to make things more consistent but unfortunately fixing inconsistencies like this in 1.5.x is very difficult.

@philwebb This is a great test case: compound prefix with nested maps. If 2.0 can bind this correctly it can likely handle anything.

@dturanski I'll make sure we add a unit test in the new code.

I've just hit a similar issue with Eureka default zone with Spring Boot 2.0.0.M7 - it doesn't seem to correctly handle camel cases when binding map elements..

@mkucharek this issue is closed. If you believe you have found an issue, please create a minimal sample (without Spring Cloud) that we can run ourselves and create a separate issue.

Was this page helpful?
0 / 5 - 0 ratings