Adds support for non-enumerable property sources in bootstrap.

Fixes gh-724
This commit is contained in:
spencergibb
2020-05-21 17:01:26 -04:00
parent a10fbb9b07
commit 26dae55042
5 changed files with 85 additions and 10 deletions

View File

@@ -416,12 +416,37 @@ public class BootstrapConfigurationTests {
.isEqualTo("Hello added!");
}
@Test
public void nonEnumerablePropertySourceWorks() {
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.sources(BareConfiguration.class)
.properties("spring.cloud.bootstrap.name=nonenumerable").run();
then(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar");
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
protected static class BareConfiguration {
}
@Configuration(proxyBeanMethods = false)
// This is added to bootstrap context as a source in bootstrap.properties
protected static class SimplePropertySourceConfiguration
implements PropertySourceLocator {
@Override
public PropertySource<?> locate(Environment environment) {
return new PropertySource("testBootstrapSimple", this) {
@Override
public Object getProperty(String name) {
return ("foo".equals(name)) ? "bar" : null;
}
};
}
}
@Configuration(proxyBeanMethods = false)
@ConfigurationProperties("expected")
// This is added to bootstrap context as a source in bootstrap.properties