Allow ConfigurationPropertiesRebinder to rebind beans by name

including ones in the parent context.
This commit is contained in:
Dave Syer
2015-07-28 13:07:37 +01:00
parent 4df29bdfe7
commit addeda8262
3 changed files with 46 additions and 25 deletions

View File

@@ -73,6 +73,19 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
assertEquals(2, this.properties.getCount());
}
@Test
@DirtiesContext
public void testRefreshByName() throws Exception {
assertEquals(1, this.properties.getCount());
assertEquals("Hello scope!", this.properties.getMessage());
// Change the dynamic property source...
EnvironmentTestUtils.addEnvironment(this.environment, "message:Foo");
// ...and then refresh, so the bean is re-initialized:
this.rebinder.rebind("properties");
assertEquals("Foo", this.properties.getMessage());
assertEquals(2, this.properties.getCount());
}
@Configuration
@EnableConfigurationProperties
@Import({RefreshConfiguration.RebinderConfiguration.class, PropertyPlaceholderAutoConfiguration.class})