Be more selective with the property sources in a context refresh
We need to tread a very fine line. Ideally the process of refreshing the Environment builds it back exactly as happened on startup. In particular we probably don't want to have things like application.properties already there when we start the process. This change replaces the more liberal copy of all property sources only a select few (actually only one), paremeterized as a constant.
This commit is contained in:
@@ -63,7 +63,7 @@ public class ContextRefresherTests {
|
||||
List<String> names = names(context.getEnvironment().getPropertySources());
|
||||
assertThat(names).doesNotContain("bootstrapProperties");
|
||||
ContextRefresher refresher = new ContextRefresher(context, scope);
|
||||
EnvironmentTestUtils.addEnvironment(context,
|
||||
EnvironmentTestUtils.addEnvironment("defaultProperties", context.getEnvironment(),
|
||||
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration\n"
|
||||
+ "");
|
||||
refresher.refresh();
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RefreshEndpointTests {
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.profiles.active=local");
|
||||
context.getEnvironment().setActiveProfiles("local");
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.invoke();
|
||||
@@ -84,8 +84,7 @@ public class RefreshEndpointTests {
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.profiles.active=override");
|
||||
context.getEnvironment().setActiveProfiles("override");
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.invoke();
|
||||
@@ -99,7 +98,7 @@ public class RefreshEndpointTests {
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
EnvironmentTestUtils.addEnvironment("defaultProperties", this.context.getEnvironment(),
|
||||
"spring.cloud.bootstrap.sources="
|
||||
+ ExternalPropertySourceLocator.class.getName());
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
|
||||
Reference in New Issue
Block a user