From 4e0fdbee17b3fbc1e452b2ada16a1ca404dd601e Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Mon, 20 Apr 2020 17:08:54 -0700 Subject: [PATCH] Process additional locations when non-default location configured Fixes gh-20745 --- .../context/config/ConfigFileApplicationListener.java | 10 ++++++---- .../config/ConfigFileApplicationListenerTests.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index b33937b87a..c852eeb202 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -622,12 +622,14 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, } private Set getSearchLocations() { + Set 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 locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY); - locations.addAll( - asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS)); return locations; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 47fc08b96f..742fa79edf 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -913,6 +913,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,