diff --git a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java index 2699efbe05..45a3cd8d45 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java @@ -76,19 +76,14 @@ class OriginTrackedYamlLoader extends YamlProcessor { public Map load() { final Map result = new LinkedHashMap(); - process(new MatchCallback() { - - @Override - public void process(Properties properties, Map map) { - result.putAll(getFlattenedMap(map)); - } - + process((properties, map) -> { + result.putAll(getFlattenedMap(map)); }); return result; } /** - * {@link Constructor}. + * {@link Constructor} that tracks property origins. */ private class OriginTrackingConstructor extends StrictMapAppenderConstructor { @@ -100,14 +95,16 @@ class OriginTrackedYamlLoader extends YamlProcessor { } } else if (node instanceof MappingNode) { - List value = ((MappingNode) node).getValue(); - List updatedValues = value.stream().map(nt -> new NodeTuple(KeyScalarNode.get(nt.getKeyNode()), - nt.getValueNode())).collect(Collectors.toList()); - ((MappingNode) node).setValue(updatedValues); + replaceMappingNodeKeys((MappingNode) node); } return super.constructObject(node); } + private void replaceMappingNodeKeys(MappingNode node) { + node.setValue(node.getValue().stream().map(KeyScalarNode::get) + .collect(Collectors.toList())); + } + private Object constructTrackedObject(Node node, Object value) { PropertyOrigin origin = getOrigin(node); return OriginTrackedValue.of(value, origin); @@ -128,7 +125,14 @@ class OriginTrackedYamlLoader extends YamlProcessor { private static class KeyScalarNode extends ScalarNode { KeyScalarNode(ScalarNode node) { - super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), node.getStyle()); + super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), + node.getStyle()); + } + + public static NodeTuple get(NodeTuple nodeTuple) { + Node keyNode = nodeTuple.getKeyNode(); + Node valueNode = nodeTuple.getValueNode(); + return new NodeTuple(KeyScalarNode.get(keyNode), valueNode); } private static Node get(Node node) { @@ -155,6 +159,10 @@ class OriginTrackedYamlLoader extends YamlProcessor { } + /** + * {@link SpringProfileDocumentMatcher} that deals with {@link OriginTrackedValue + * OriginTrackedValues}. + */ private static class OriginTrackedSpringProfileDocumentMatcher extends SpringProfileDocumentMatcher { diff --git a/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java index 4003f29f61..c86f27a968 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.testutil.MockServlet; -import org.springframework.boot.web.servlet.context.config.ExampleEmbeddedWebApplicationConfiguration; +import org.springframework.boot.web.servlet.context.config.ExampleServletWebServerApplicationConfiguration; import org.springframework.boot.web.servlet.server.MockServletWebServerFactory; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; @@ -55,14 +55,15 @@ public class AnnotationConfigServletWebServerApplicationContextTests { @Test public void createFromScan() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext( - ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName()); + ExampleServletWebServerApplicationConfiguration.class.getPackage() + .getName()); verifyContext(); } @Test public void sessionScopeAvailable() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext( - ExampleEmbeddedWebApplicationConfiguration.class, + ExampleServletWebServerApplicationConfiguration.class, SessionScopedComponent.class); verifyContext(); } @@ -70,7 +71,7 @@ public class AnnotationConfigServletWebServerApplicationContextTests { @Test public void sessionScopeAvailableToServlet() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext( - ExampleEmbeddedWebApplicationConfiguration.class, + ExampleServletWebServerApplicationConfiguration.class, ExampleServletWithAutowired.class, SessionScopedComponent.class); Servlet servlet = this.context.getBean(ExampleServletWithAutowired.class); assertThat(servlet).isNotNull(); @@ -79,14 +80,14 @@ public class AnnotationConfigServletWebServerApplicationContextTests { @Test public void createFromConfigClass() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext( - ExampleEmbeddedWebApplicationConfiguration.class); + ExampleServletWebServerApplicationConfiguration.class); verifyContext(); } @Test public void registerAndRefresh() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext(); - this.context.register(ExampleEmbeddedWebApplicationConfiguration.class); + this.context.register(ExampleServletWebServerApplicationConfiguration.class); this.context.refresh(); verifyContext(); } @@ -94,8 +95,8 @@ public class AnnotationConfigServletWebServerApplicationContextTests { @Test public void scanAndRefresh() throws Exception { this.context = new AnnotationConfigServletWebServerApplicationContext(); - this.context.scan( - ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName()); + this.context.scan(ExampleServletWebServerApplicationConfiguration.class + .getPackage().getName()); this.context.refresh(); verifyContext(); } diff --git a/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleServletWebServerApplicationConfiguration.java similarity index 95% rename from spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java rename to spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleServletWebServerApplicationConfiguration.java index 1900648401..b6586beb7b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleEmbeddedWebApplicationConfiguration.java +++ b/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/config/ExampleServletWebServerApplicationConfiguration.java @@ -31,7 +31,7 @@ import org.springframework.context.annotation.Configuration; * @author Phillip Webb */ @Configuration -public class ExampleEmbeddedWebApplicationConfiguration { +public class ExampleServletWebServerApplicationConfiguration { @Bean public MockServletWebServerFactory webServerFactory() {