Merge branch 'master' into 2.0.x
# Conflicts: # spring-cloud-context/src/test/java/org/springframework/cloud/context/refresh/ContextRefresherTests.java
This commit is contained in:
@@ -17,6 +17,7 @@ import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.CommandLinePropertySource;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.EnumerablePropertySource;
|
||||
@@ -34,8 +35,9 @@ public class ContextRefresher {
|
||||
|
||||
private static final String REFRESH_ARGS_PROPERTY_SOURCE = "refreshArgs";
|
||||
|
||||
private static final String[] DEFAULT_PROPERTY_SOURCES = new String[] {
|
||||
"defaultProperties" };
|
||||
private static final String[] DEFAULT_PROPERTY_SOURCES = new String[] { //order matters, cli args aren't first, things get messy
|
||||
CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
|
||||
"defaultProperties"};
|
||||
|
||||
private Set<String> standardSources = new HashSet<>(
|
||||
Arrays.asList(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -17,12 +21,27 @@ import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapCon
|
||||
*/
|
||||
@Order(0)
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public class TestBootstrapConfiguration {
|
||||
|
||||
public TestBootstrapConfiguration() {
|
||||
firstToBeCreated.compareAndSet(null, TestBootstrapConfiguration.class);
|
||||
}
|
||||
|
||||
public static List<String> fooSightings = null;
|
||||
|
||||
@Bean
|
||||
@Qualifier("foo-during-bootstrap")
|
||||
public String fooDuringBootstrap(ConfigurableEnvironment environment, ApplicationEventPublisher publisher) {
|
||||
String property = environment.getProperty("test.bootstrap.foo", "undefined");
|
||||
|
||||
if (fooSightings != null) {
|
||||
fooSightings.add(property);
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationContextInitializer<ConfigurableApplicationContext> customInitializer() {
|
||||
return new ApplicationContextInitializer<ConfigurableApplicationContext>() {
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.logging.LoggingSystem;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.test.util.TestPropertyValues.Type;
|
||||
import org.springframework.cloud.bootstrap.TestBootstrapConfiguration;
|
||||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -117,6 +117,27 @@ public class ContextRefresherTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void commandLineArgsPassedToBootstrapConfiguration() {
|
||||
|
||||
TestBootstrapConfiguration.fooSightings = new ArrayList<>();
|
||||
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(ContextRefresherTests.class,
|
||||
"--spring.main.webEnvironment=false", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh",
|
||||
"--test.bootstrap.foo=bar")) {
|
||||
context.getEnvironment().setActiveProfiles("refresh");
|
||||
ContextRefresher refresher = new ContextRefresher(context, scope);
|
||||
refresher.refresh();
|
||||
assertThat(TestBootstrapConfiguration.fooSightings).containsExactly("bar", "bar");
|
||||
}
|
||||
|
||||
TestBootstrapConfiguration.fooSightings = null;
|
||||
}
|
||||
|
||||
|
||||
private List<String> names(MutablePropertySources propertySources) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (PropertySource<?> p : propertySources) {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
info.name: refresh-child
|
||||
test.bootstrap.foo: refresh
|
||||
Reference in New Issue
Block a user