Restore loading order of 'application.properties'
Restore the order that `ConfigFileApplicationListener` attempts to load application.properties so that local files always have a higher precedence than bundled classpath files. This fixes a regression introduced with 1.0.0.RC2. Fixes gh-370
This commit is contained in:
@@ -96,8 +96,8 @@ public class ConfigFileApplicationListener implements
|
||||
|
||||
private static final String CONFIG_LOCATION_PROPERTY = "spring.config.location";
|
||||
|
||||
private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,file:./,"
|
||||
+ "classpath:/config/,file:./config/";
|
||||
private static final String DEFAULT_SEARCH_LOCATIONS = "file:./,file:./config/,"
|
||||
+ "classpath:/,classpath:/config/";
|
||||
|
||||
private static final String DEFAULT_NAMES = "application";
|
||||
|
||||
@@ -192,6 +192,8 @@ public class ConfigFileApplicationListener implements
|
||||
|
||||
/**
|
||||
* Set the search locations that will be considered as a comma-separated list.
|
||||
* Locations are considered in the order specified, with earlier items taking
|
||||
* precedence.
|
||||
*/
|
||||
public void setSearchLocations(String locations) {
|
||||
Assert.hasLength(locations, "Locations must not be empty");
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package org.springframework.boot.context.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
@@ -93,6 +97,29 @@ public class ConfigFileApplicationListenerTests {
|
||||
assertThat(property, equalTo("frompropertiesfile"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localFileTakesPrecedenceOverClasspath() throws Exception {
|
||||
File localFile = new File(new File("."), "application.properties");
|
||||
assertThat(localFile.exists(), equalTo(false));
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.put("my.property", "fromlocalfile");
|
||||
OutputStream out = new FileOutputStream(localFile);
|
||||
try {
|
||||
properties.store(out, "");
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
this.initializer.onApplicationEvent(this.event);
|
||||
String property = this.environment.getProperty("my.property");
|
||||
assertThat(property, equalTo("fromlocalfile"));
|
||||
}
|
||||
finally {
|
||||
localFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadTwoOfThreePropertiesFile() throws Exception {
|
||||
EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:"
|
||||
|
||||
Reference in New Issue
Block a user