Process additional locations when non-default location configured
Fixes gh-20745
This commit is contained in:
@@ -622,12 +622,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getSearchLocations() {
|
private Set<String> getSearchLocations() {
|
||||||
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
|
|
||||||
return getSearchLocations(CONFIG_LOCATION_PROPERTY);
|
|
||||||
}
|
|
||||||
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
|
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
|
||||||
locations.addAll(
|
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
|
||||||
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
|
locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
locations.addAll(
|
||||||
|
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
|
||||||
|
}
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -913,6 +913,16 @@ class ConfigFileApplicationListenerTests {
|
|||||||
assertThat(this.environment.getProperty("value")).isEqualTo("1234");
|
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
|
@Test
|
||||||
void locationReplaceDefaultLocation() {
|
void locationReplaceDefaultLocation() {
|
||||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
||||||
|
|||||||
Reference in New Issue
Block a user