diff --git a/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java b/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java index 0fdd253ae1..58e8bde5f4 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/YamlPropertySourceLoader.java @@ -78,10 +78,10 @@ public class YamlPropertySourceLoader implements PropertySourceLoader { process(new MatchCallback() { @Override public void process(Properties properties, Map map) { - result.putAll(map); + result.putAll(getFlattenedMap(map)); } }); - return getFlattenedMap(result); + return result; } } diff --git a/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java b/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java index 323a57e585..c2bf7ce3c3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderTests.java @@ -62,4 +62,17 @@ public class YamlPropertySourceLoaderTests { assertThat(source.getPropertyNames(), equalTo(expected.toArray(new String[] {}))); } + @Test + public void mergeItems() throws Exception { + StringBuilder yaml = new StringBuilder(); + yaml.append("foo:\n bar: spam\n"); + yaml.append("---\n"); + yaml.append("foo:\n baz: wham\n"); + ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes()); + PropertySource source = this.loader.load("resource", resource, null); + assertNotNull(source); + assertEquals("spam", source.getProperty("foo.bar")); + assertEquals("wham", source.getProperty("foo.baz")); + } + }