Browse Source

Merge branch '2.2.x'

Closes gh-21050
pull/21054/head
Madhura Bhave 6 years ago
parent
commit
5d56d652fb
  1. 10
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java
  2. 10
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

10
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

@ -638,12 +638,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, @@ -638,12 +638,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
private Set<String> getSearchLocations() {
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
return getSearchLocations(CONFIG_LOCATION_PROPERTY);
locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
}
else {
locations.addAll(
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
}
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
locations.addAll(
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
return locations;
}

10
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

@ -925,6 +925,16 @@ class ConfigFileApplicationListenerTests { @@ -925,6 +925,16 @@ class ConfigFileApplicationListenerTests {
assertThat(this.environment.getProperty("value")).isEqualTo("1234");
}
@Test
void additionalLocationWhenLocationConfiguredShouldTakesPrecedenceOverConfiguredLocation() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
"spring.config.location=classpath:some.properties",
"spring.config.additional-location=classpath:override.properties");
this.initializer.postProcessEnvironment(this.environment, this.application);
assertThat(this.environment.getProperty("foo")).isEqualTo("bar");
assertThat(this.environment.getProperty("value")).isNull();
}
@Test
void locationReplaceDefaultLocation() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,

Loading…
Cancel
Save