Skip to content

Commit 5d1ff69

Browse files
committed
Reuse EnvironmentPostProcessorsFactory provided by Spring Boot
Signed-off-by: Yanming Zhou <[email protected]>
1 parent a3ef42f commit 5d1ff69

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@
2424

2525
import org.springframework.boot.EnvironmentPostProcessor;
2626
import org.springframework.boot.SpringApplication;
27-
import org.springframework.boot.bootstrap.BootstrapContext;
28-
import org.springframework.boot.bootstrap.BootstrapRegistry;
2927
import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
3028
import org.springframework.boot.bootstrap.DefaultBootstrapContext;
3129
import org.springframework.boot.logging.DeferredLogFactory;
32-
import org.springframework.boot.util.Instantiator;
30+
import org.springframework.boot.support.EnvironmentPostProcessorsFactory;
3331
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
3432
import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
3533
import org.springframework.cloud.context.scope.refresh.RefreshScope;
@@ -38,11 +36,11 @@
3836
import org.springframework.core.env.MutablePropertySources;
3937
import org.springframework.core.env.PropertySource;
4038
import org.springframework.core.env.StandardEnvironment;
41-
import org.springframework.core.io.support.SpringFactoriesLoader;
4239

4340
/**
4441
* @author Dave Syer
4542
* @author Venil Noronha
43+
* @author Yanming Zhou
4644
*/
4745
public class ConfigDataContextRefresher extends ContextRefresher
4846
implements ApplicationListener<ContextRefreshedWithApplicationEvent> {
@@ -77,17 +75,10 @@ protected void updateEnvironment() {
7775
// decrypt happen after refresh. The hard coded call to
7876
// ConfigDataEnvironmentPostProcessor.applyTo() is now automated as well.
7977
DeferredLogFactory logFactory = new PassthruDeferredLogFactory();
80-
List<String> classNames = SpringFactoriesLoader.loadFactoryNames(EnvironmentPostProcessor.class,
81-
getClass().getClassLoader());
82-
Instantiator<EnvironmentPostProcessor> instantiator = new Instantiator<>(EnvironmentPostProcessor.class,
83-
(parameters) -> {
84-
parameters.add(DeferredLogFactory.class, logFactory);
85-
parameters.add(Log.class, logFactory::getLog);
86-
parameters.add(ConfigurableBootstrapContext.class, bootstrapContext);
87-
parameters.add(BootstrapContext.class, bootstrapContext);
88-
parameters.add(BootstrapRegistry.class, bootstrapContext);
89-
});
90-
List<EnvironmentPostProcessor> postProcessors = instantiator.instantiate(classNames);
78+
EnvironmentPostProcessorsFactory postProcessorsFactory = EnvironmentPostProcessorsFactory
79+
.fromSpringFactories(getClass().getClassLoader());
80+
List<EnvironmentPostProcessor> postProcessors = postProcessorsFactory.getEnvironmentPostProcessors(logFactory,
81+
bootstrapContext);
9182
for (EnvironmentPostProcessor postProcessor : postProcessors) {
9283
postProcessor.postProcessEnvironment(environment, application);
9384
}

0 commit comments

Comments
 (0)