Makes ContextRefresher easier to extend.

Adds protected getters for context and scope.

Adds new refreshEnvironment() method.

fixes gh-382
This commit is contained in:
Spencer Gibb
2018-08-15 14:48:58 -04:00
parent 69181c14d1
commit 6533e0ca53

View File

@@ -56,14 +56,27 @@ public class ContextRefresher {
this.scope = scope;
}
protected ConfigurableApplicationContext getContext() {
return this.context;
}
protected RefreshScope getScope() {
return this.scope;
}
public synchronized Set<String> refresh() {
Set<String> keys = refreshEnvironment();
this.scope.refreshAll();
return keys;
}
public synchronized Set<String> refreshEnvironment() {
Map<String, Object> before = extract(
this.context.getEnvironment().getPropertySources());
addConfigFilesToEnvironment();
Set<String> keys = changes(before,
extract(this.context.getEnvironment().getPropertySources())).keySet();
this.context.publishEvent(new EnvironmentChangeEvent(context, keys));
this.scope.refreshAll();
return keys;
}