From 06494e068fbd051afe853ec05b2d78fef18d5879 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 11 Feb 2014 17:15:27 -0800 Subject: [PATCH] Consistent property source ordering with names Update ConfigFileApplicationListener so that custom names and custom locations use consistent ordering. i.e. earlier items take precedence (same as @ProperySource). --- .../boot/config/ConfigFileApplicationListener.java | 8 ++++---- .../boot/config/ConfigFileApplicationListenerTests.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/config/ConfigFileApplicationListener.java index 14b619f374..2a25d86846 100644 --- a/spring-boot/src/main/java/org/springframework/boot/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/config/ConfigFileApplicationListener.java @@ -369,12 +369,12 @@ public class ConfigFileApplicationListener implements private void addLoadCandidatesFromSearchLocations( ConfigurableEnvironment environment, Set candidates) { + String[] names = StringUtils.commaDelimitedListToStringArray(environment + .resolvePlaceholders(ConfigFileApplicationListener.this.names)); for (String location : ConfigFileApplicationListener.this.searchLocations) { for (String extension : new String[] { ".properties", ".yml" }) { - for (String name : StringUtils - .commaDelimitedListToStringArray(environment - .resolvePlaceholders(ConfigFileApplicationListener.this.names))) { - candidates.add(location + name + extension); + for (int i = names.length - 1; i >= 0; i--) { + candidates.add(location + names[i] + extension); } } } diff --git a/spring-boot/src/test/java/org/springframework/boot/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/config/ConfigFileApplicationListenerTests.java index 86b6b30026..5a6bd80657 100644 --- a/spring-boot/src/test/java/org/springframework/boot/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/config/ConfigFileApplicationListenerTests.java @@ -108,7 +108,7 @@ public class ConfigFileApplicationListenerTests { @Test public void loadTwoPropertiesFiles() throws Exception { - this.initializer.setNames("testproperties,moreproperties"); + this.initializer.setNames("moreproperties,testproperties"); this.initializer.onApplicationEvent(this.event); String property = this.environment.getProperty("my.property"); assertThat(property, equalTo("frommorepropertiesfile"));