Attach ConfigurationPropertiesSource

Update `SpringApplication` to automatically attached the
`ConfigurationPropertiesSource` when a `SpringApplication` runs.

See gh-4910
pull/8802/merge
Phillip Webb 8 years ago
parent 813128a410
commit 16f9ef4f6a

@ -42,6 +42,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.boot.Banner.Mode; import org.springframework.boot.Banner.Mode;
import org.springframework.boot.bind.PropertiesConfigurationFactory; import org.springframework.boot.bind.PropertiesConfigurationFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
@ -375,6 +376,7 @@ public class SpringApplication {
&& this.webApplicationType == WebApplicationType.NONE) { && this.webApplicationType == WebApplicationType.NONE) {
environment = convertToStandardEnvironment(environment); environment = convertToStandardEnvironment(environment);
} }
ConfigurationPropertySources.attach(environment);
return environment; return environment;
} }

@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; 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.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent; 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.testutil.InternalOutputCapture;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
@ -866,9 +868,12 @@ public class SpringApplicationTests {
assertThat(this.context.getEnvironment()) assertThat(this.context.getEnvironment())
.isNotInstanceOf(StandardServletEnvironment.class); .isNotInstanceOf(StandardServletEnvironment.class);
assertThat(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar"); assertThat(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar");
assertThat(this.context.getEnvironment().getPropertySources().iterator().next() Iterator<PropertySource<?>> iterator = this.context.getEnvironment()
.getName()).isEqualTo( .getPropertySources().iterator();
TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); assertThat(iterator.next().getName())
.isEqualTo(ConfigurationPropertySources.PROPERTY_SOURCE_NAME);
assertThat(iterator.next().getName()).isEqualTo(
TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME);
} }
@Test @Test

Loading…
Cancel
Save