Allow system property override to be switched off
The default behaviour is the same as before, so a config client adds the remote property sources "first" (i.e. ahead of system properties). If the user sets up a remote config repo with spring.cloud.config.overrideSystemProperties=false they can change this behaviour and insert the new property source after systemEnvironment (i.e. before local config files but after the other local sources). Of course using an `application.yml` on the server you can change the default for all applications. There is also a new feature in the config server where the operator can add a map of override properties in spring.cloud.config.server.overrides.* and have them added with highest priority in the Environment returned from the server. Using that the operator can prevent config repositories from changing the override behaviour by setting spring.cloud.config.allowOverride=false. Fixes gh-57
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -35,6 +36,8 @@ public class ApplicationTests {
|
||||
public void contextLoads() {
|
||||
Environment environment = new TestRestTemplate().getForObject("http://localhost:" + port + "/foo/development/", Environment.class);
|
||||
assertFalse(environment.getPropertySources().isEmpty());
|
||||
assertEquals("overrides", environment.getPropertySources().get(0).getName());
|
||||
assertEquals("{spring.cloud.config.enabled=true}", environment.getPropertySources().get(0).getSource().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -38,7 +39,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
*
|
||||
*/
|
||||
public class EnvironmentControllerTests {
|
||||
|
||||
|
||||
@Rule
|
||||
public ExpectedException expected = ExpectedException.none();
|
||||
|
||||
@@ -120,9 +121,22 @@ public class EnvironmentControllerTests {
|
||||
|
||||
@Test
|
||||
public void mappingForLabelledYamlWithHyphen() throws Exception {
|
||||
Mockito.when(repository.findOne("foo", "bar-spam", "other")).thenReturn(environment);
|
||||
Mockito.when(repository.findOne("foo", "bar-spam", "other")).thenReturn(
|
||||
environment);
|
||||
MockMvc mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
mvc.perform(MockMvcRequestBuilders.get("/other/foo-bar-spam.yml")).andExpect(
|
||||
MockMvcResultMatchers.status().isBadRequest());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowOverrideFalse() throws Exception {
|
||||
controller.setOverrides(Collections.singletonMap("foo", "bar"));
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("a.b.c", "d");
|
||||
environment.add(new PropertySource("one", map));
|
||||
Mockito.when(repository.findOne("foo", "bar", "master")).thenReturn(environment);
|
||||
assertEquals("{foo=bar}", controller.master("foo", "bar").getPropertySources()
|
||||
.get(0).getSource().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,3 +4,8 @@ spring:
|
||||
server:
|
||||
git:
|
||||
basedir: target/config
|
||||
overrides:
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
enabled: true
|
||||
Reference in New Issue
Block a user