Browse Source

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).
pull/236/merge
Phillip Webb 12 years ago
parent
commit
06494e068f
  1. 8
      spring-boot/src/main/java/org/springframework/boot/config/ConfigFileApplicationListener.java
  2. 2
      spring-boot/src/test/java/org/springframework/boot/config/ConfigFileApplicationListenerTests.java

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

@ -369,12 +369,12 @@ public class ConfigFileApplicationListener implements @@ -369,12 +369,12 @@ public class ConfigFileApplicationListener implements
private void addLoadCandidatesFromSearchLocations(
ConfigurableEnvironment environment, Set<String> 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);
}
}
}

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

@ -108,7 +108,7 @@ public class ConfigFileApplicationListenerTests { @@ -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"));

Loading…
Cancel
Save