Add test to support binding nested properties

See gh-3539
This commit is contained in:
Dave Syer 2015-08-10 11:22:47 +01:00
parent 2985b0e9d8
commit ce512a18f3

View File

@ -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;
}
}
}
}