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:
Dave Syer
2017-11-03 14:01:29 +00:00
parent e388b5c4d2
commit 91f60b3f4c
3 changed files with 19 additions and 10 deletions

View File

@@ -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();

View File

@@ -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);