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).
This commit is contained in:
Phillip Webb
2014-02-11 17:15:27 -08:00
parent 52c4205945
commit 06494e068f
2 changed files with 5 additions and 5 deletions

View File

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

View File

@@ -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"));