Browse Source

Merge branch 'master' into 2.0.x

pull/284/head
Spencer Gibb 7 years ago
parent
commit
f302c166a5
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 21
      spring-cloud-context/src/main/java/org/springframework/cloud/context/refresh/ContextRefresher.java
  2. 16
      spring-cloud-context/src/test/java/org/springframework/cloud/context/refresh/ContextRefresherTests.java

21
spring-cloud-context/src/main/java/org/springframework/cloud/context/refresh/ContextRefresher.java

@ -34,7 +34,7 @@ public class ContextRefresher { @@ -34,7 +34,7 @@ public class ContextRefresher {
private static final String REFRESH_ARGS_PROPERTY_SOURCE = "refreshArgs";
private Set<String> standardSources = new HashSet<String>(
private Set<String> standardSources = new HashSet<>(
Arrays.asList(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME,
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME,
@ -61,7 +61,7 @@ public class ContextRefresher { @@ -61,7 +61,7 @@ public class ContextRefresher {
return keys;
}
private void addConfigFilesToEnvironment() {
/* for testing */ ConfigurableApplicationContext addConfigFilesToEnvironment() {
ConfigurableApplicationContext capture = null;
try {
StandardEnvironment environment = copyEnvironment(
@ -105,9 +105,22 @@ public class ContextRefresher { @@ -105,9 +105,22 @@ public class ContextRefresher {
}
finally {
ConfigurableApplicationContext closeable = capture;
closeable.close();
while (closeable != null) {
try {
closeable.close();
}
catch (Exception e) {
// Ignore;
}
if (closeable.getParent() instanceof ConfigurableApplicationContext) {
closeable = (ConfigurableApplicationContext) closeable.getParent();
}
else {
break;
}
}
}
return capture;
}
// Don't use ConfigurableEnvironment.merge() in case there are clashes with property

16
spring-cloud-context/src/test/java/org/springframework/cloud/context/refresh/ContextRefresherTests.java

@ -66,6 +66,22 @@ public class ContextRefresherTests { @@ -66,6 +66,22 @@ public class ContextRefresherTests {
}
}
@Test
public void parentContextIsClosed() {
// Use spring.cloud.bootstrap.name to switch off the defaults (which would pick up
// a bootstrapProperties immediately
context = SpringApplication.run(ContextRefresherTests.class,
"--spring.main.webEnvironment=false", "--debug=false",
"--spring.main.bannerMode=OFF", "--spring.cloud.bootstrap.name=refresh");
ContextRefresher refresher = new ContextRefresher(context, scope);
EnvironmentTestUtils.addEnvironment(context,
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration\n"
+ "");
ConfigurableApplicationContext refresherContext = refresher.addConfigFilesToEnvironment();
assertThat(refresherContext.getParent()).isNotNull().isInstanceOf(ConfigurableApplicationContext.class);
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) refresherContext.getParent();
assertThat(parent.isActive()).isFalse();
}
private List<String> names(MutablePropertySources propertySources) {
List<String> list = new ArrayList<>();
for (PropertySource<?> p : propertySources) {

Loading…
Cancel
Save