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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user