From 16f9ef4f6af8233a624aaec85becf69b0d326aea Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 25 Apr 2017 10:59:17 -0700 Subject: [PATCH] Attach ConfigurationPropertiesSource Update `SpringApplication` to automatically attached the `ConfigurationPropertiesSource` when a `SpringApplication` runs. See gh-4910 --- .../org/springframework/boot/SpringApplication.java | 2 ++ .../springframework/boot/SpringApplicationTests.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 8579230fe19..823c77310ef 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -42,6 +42,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.boot.Banner.Mode; import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationListener; @@ -375,6 +376,7 @@ public class SpringApplication { && this.webApplicationType == WebApplicationType.NONE) { environment = convertToStandardEnvironment(environment); } + ConfigurationPropertySources.attach(environment); return environment; } diff --git a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java index 5dad01ce3ba..fc66965f9ea 100644 --- a/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -47,6 +48,7 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationStartingEvent; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.testutil.InternalOutputCapture; import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -866,9 +868,12 @@ public class SpringApplicationTests { assertThat(this.context.getEnvironment()) .isNotInstanceOf(StandardServletEnvironment.class); assertThat(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar"); - assertThat(this.context.getEnvironment().getPropertySources().iterator().next() - .getName()).isEqualTo( - TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); + Iterator> iterator = this.context.getEnvironment() + .getPropertySources().iterator(); + assertThat(iterator.next().getName()) + .isEqualTo(ConfigurationPropertySources.PROPERTY_SOURCE_NAME); + assertThat(iterator.next().getName()).isEqualTo( + TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); } @Test