Skip to content

Commit 5d56d65

Browse files
committed
Merge branch '2.2.x'
Closes gh-21050
2 parents 7755e0c + 4e0fdbe commit 5d56d65

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,14 @@ private void addProfileToEnvironment(String profile) {
638638
}
639639

640640
private Set<String> getSearchLocations() {
641+
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
641642
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
642-
return getSearchLocations(CONFIG_LOCATION_PROPERTY);
643+
locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
644+
}
645+
else {
646+
locations.addAll(
647+
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
643648
}
644-
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
645-
locations.addAll(
646-
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
647649
return locations;
648650
}
649651

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,16 @@ void lastAdditionalLocationWins() {
925925
assertThat(this.environment.getProperty("value")).isEqualTo("1234");
926926
}
927927

928+
@Test
929+
void additionalLocationWhenLocationConfiguredShouldTakesPrecedenceOverConfiguredLocation() {
930+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
931+
"spring.config.location=classpath:some.properties",
932+
"spring.config.additional-location=classpath:override.properties");
933+
this.initializer.postProcessEnvironment(this.environment, this.application);
934+
assertThat(this.environment.getProperty("foo")).isEqualTo("bar");
935+
assertThat(this.environment.getProperty("value")).isNull();
936+
}
937+
928938
@Test
929939
void locationReplaceDefaultLocation() {
930940
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,

0 commit comments

Comments
 (0)