Skip to content

Commit

Permalink
Process additional locations when non-default location configured
Browse files Browse the repository at this point in the history
Fixes gh-20745
  • Loading branch information
mbhave committed Apr 21, 2020
1 parent af6d538 commit 4e0fdbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -622,12 +622,14 @@ private void addProfileToEnvironment(String profile) {
}

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;
}

Expand Down
Expand Up @@ -913,6 +913,16 @@ void lastAdditionalLocationWins() {
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,
Expand Down

0 comments on commit 4e0fdbe

Please sign in to comment.