Add flag spring.cloud.config.overrideNone

If true (and spring.cloud.config.allowOverride=true) then the bootstrap
property source is added *last*, so all other property sources can override
it (including local config files).

Fixes gh-26, fixes gh-27.
This commit is contained in:
Dave Syer
2015-04-28 12:22:14 +01:00
parent ecaecb6d32
commit 9d4584bb5c
3 changed files with 59 additions and 6 deletions

View File

@@ -156,6 +156,32 @@ public class BootstrapConfigurationTests {
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
}
@Test
public void systemPropertyOverrideFalseWhenOverrideAllowed() {
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
PropertySourceConfiguration.MAP.put(
"spring.cloud.config.overrideSystemProperties", "false");
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true");
System.setProperty("bootstrap.foo", "system");
this.context = new SpringApplicationBuilder().web(false)
.sources(BareConfiguration.class).run();
assertEquals("system", this.context.getEnvironment().getProperty("bootstrap.foo"));
}
@Test
public void overrideAllWhenOverrideAllowed() {
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
PropertySourceConfiguration.MAP.put("spring.cloud.config.overrideNone", "true");
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true");
ConfigurableEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addLast(
new MapPropertySource("last", Collections.<String, Object> singletonMap(
"bootstrap.foo", "splat")));
this.context = new SpringApplicationBuilder().web(false).environment(environment)
.sources(BareConfiguration.class).run();
assertEquals("splat", this.context.getEnvironment().getProperty("bootstrap.foo"));
}
@Test
public void applicationNameInBootstrapAndMain() {
System.setProperty("expected.name", "main");