From ce512a18f3b66b847444b49842b85bbf17d3193c Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 10 Aug 2015 11:22:47 +0100 Subject: [PATCH] Add test to support binding nested properties See gh-3539 --- ...onPropertiesBindingPostProcessorTests.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java index e6f5590d5c..0a10edb001 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java @@ -293,6 +293,17 @@ public class ConfigurationPropertiesBindingPostProcessorTests { equalTo("test2")); } + @Test + public void nestedProperties() throws Exception { + // gh-3539 + this.context = new AnnotationConfigApplicationContext(); + EnvironmentTestUtils.addEnvironment(this.context, "TEST_NESTED_VALUE:test1"); + this.context.register(PropertyWithNestedValue.class); + this.context.refresh(); + assertThat(this.context.getBean(PropertyWithNestedValue.class).getNested() + .getValue(), equalTo("test1")); + } + @Configuration @EnableConfigurationProperties public static class TestConfigurationWithValidatingSetter { @@ -612,4 +623,37 @@ public class ConfigurationPropertiesBindingPostProcessorTests { } + @Configuration + @EnableConfigurationProperties + @ConfigurationProperties(prefix = "test") + public static class PropertyWithNestedValue { + + private Nested nested = new Nested(); + + public Nested getNested() { + return this.nested; + } + + @Bean + public static PropertySourcesPlaceholderConfigurer configurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + + public static class Nested { + + @Value("${default.value}") + private String value; + + public void setValue(String value) { + this.value = value; + } + + public String getValue() { + return this.value; + } + + } + + } + }