mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Change order of config file locations to be more natural
The most natural order is "more specific locations win". That way if a use has application.properties in the root of a JAR (as is normal), overrides can always be made on classpath:/config/application.properties (as well as file:./application.properties which has always been the case). Before this change properties in classpath:/config/* were over written by those in the root location, not the other way round. Fixes gh-527
This commit is contained in:
parent
d6be3dfbb0
commit
a47d5ccd44
@ -96,8 +96,8 @@ public class ConfigFileApplicationListener implements
|
|||||||
|
|
||||||
private static final String CONFIG_LOCATION_PROPERTY = "spring.config.location";
|
private static final String CONFIG_LOCATION_PROPERTY = "spring.config.location";
|
||||||
|
|
||||||
private static final String DEFAULT_SEARCH_LOCATIONS = "file:./,file:./config/,"
|
private static final String DEFAULT_SEARCH_LOCATIONS = "file:./config/,file:./,"
|
||||||
+ "classpath:/,classpath:/config/";
|
+ "classpath:/config/,classpath:/";
|
||||||
|
|
||||||
private static final String DEFAULT_NAMES = "application";
|
private static final String DEFAULT_NAMES = "application";
|
||||||
|
|
||||||
|
@ -133,6 +133,15 @@ public class ConfigFileApplicationListenerTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void moreSpecificLocationTakesPrecedenceOverRoot() throws Exception {
|
||||||
|
EnvironmentTestUtils.addEnvironment(this.environment,
|
||||||
|
"spring.config.name:specific");
|
||||||
|
this.initializer.onApplicationEvent(this.event);
|
||||||
|
String property = this.environment.getProperty("my.property");
|
||||||
|
assertThat(property, equalTo("specific"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loadTwoOfThreePropertiesFile() throws Exception {
|
public void loadTwoOfThreePropertiesFile() throws Exception {
|
||||||
EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:"
|
EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:"
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
my.property=specific
|
1
spring-boot/src/test/resources/specific.properties
Normal file
1
spring-boot/src/test/resources/specific.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
my.property=root
|
Loading…
Reference in New Issue
Block a user