diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index bf45646b26..3aaad79a91 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -152,12 +152,7 @@ public class ConfigFileApplicationListener implements ResourceLoader resourceLoader) { RandomValuePropertySource.addToEnvironment(environment); try { - PropertySource defaultProperties = environment.getPropertySources() - .remove(DEFAULT_PROPERTIES); new Loader(environment, resourceLoader).load(); - if (defaultProperties != null) { - environment.getPropertySources().addLast(defaultProperties); - } } catch (IOException ex) { throw new IllegalStateException("Unable to load configuration files", ex); @@ -456,6 +451,7 @@ public class ConfigFileApplicationListener implements for (PropertySource item : sources) { reorderedSources.add(item); } + // Maybe we should add before the DEFAULT_PROPERTIES if it exists? this.environment.getPropertySources().addLast( new ConfigurationPropertySources(reorderedSources)); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 5c3a10075d..38d2043a2e 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -23,6 +23,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Properties; @@ -43,6 +44,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.SimpleCommandLinePropertySource; import org.springframework.core.env.StandardEnvironment; @@ -260,6 +262,33 @@ public class ConfigFileApplicationListenerTests { assertThat(property, equalTo("fromsystem")); } + @Test + public void defaultPropertyAsFallback() throws Exception { + this.event + .getEnvironment() + .getPropertySources() + .addLast( + new MapPropertySource("defaultProperties", Collections + .singletonMap("my.fallback", (Object) "foo"))); + this.initializer.onApplicationEvent(this.event); + String property = this.environment.getProperty("my.fallback"); + assertThat(property, equalTo("foo")); + } + + @Test + public void defaultPropertyAsFallbackDuringFileParsing() throws Exception { + this.event + .getEnvironment() + .getPropertySources() + .addLast( + new MapPropertySource("defaultProperties", Collections + .singletonMap("spring.config.name", + (Object) "testproperties"))); + this.initializer.onApplicationEvent(this.event); + String property = this.environment.getProperty("my.property"); + assertThat(property, equalTo("frompropertiesfile")); + } + @Test public void loadPropertiesThenProfilePropertiesActivatedInSpringApplication() throws Exception { diff --git a/spring-boot/src/test/resources/application.properties b/spring-boot/src/test/resources/application.properties index 7cc1ee4906..2f0172e0f2 100644 --- a/spring-boot/src/test/resources/application.properties +++ b/spring-boot/src/test/resources/application.properties @@ -2,3 +2,4 @@ foo: bucket value: 1234 my.property: fromapplicationproperties sample.app.test.prop: * +my.placeholder: ${my.fallback}