Skip to content

Commit fed59e2

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

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
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;
29+
import org.springframework.boot.ConfigurableBootstrapContext;
30+
import org.springframework.boot.DefaultBootstrapContext;
31+
import org.springframework.boot.SpringApplication;
32+
import org.springframework.boot.env.EnvironmentPostProcessor;
33+
import org.springframework.boot.env.EnvironmentPostProcessorsFactory;
3134
import org.springframework.boot.logging.DeferredLogFactory;
32-
import org.springframework.boot.util.Instantiator;
3335
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
3436
import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
3537
import org.springframework.cloud.context.scope.refresh.RefreshScope;
@@ -38,11 +40,11 @@
3840
import org.springframework.core.env.MutablePropertySources;
3941
import org.springframework.core.env.PropertySource;
4042
import org.springframework.core.env.StandardEnvironment;
41-
import org.springframework.core.io.support.SpringFactoriesLoader;
4243

4344
/**
4445
* @author Dave Syer
4546
* @author Venil Noronha
47+
* @author Yanming Zhou
4648
*/
4749
public class ConfigDataContextRefresher extends ContextRefresher
4850
implements ApplicationListener<ContextRefreshedWithApplicationEvent> {
@@ -77,17 +79,10 @@ protected void updateEnvironment() {
7779
// decrypt happen after refresh. The hard coded call to
7880
// ConfigDataEnvironmentPostProcessor.applyTo() is now automated as well.
7981
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);
82+
EnvironmentPostProcessorsFactory postProcessorsFactory = EnvironmentPostProcessorsFactory
83+
.fromSpringFactories(getClass().getClassLoader());
84+
List<EnvironmentPostProcessor> postProcessors = postProcessorsFactory.getEnvironmentPostProcessors(logFactory,
85+
bootstrapContext);
9186
for (EnvironmentPostProcessor postProcessor : postProcessors) {
9287
postProcessor.postProcessEnvironment(environment, application);
9388
}

0 commit comments

Comments
 (0)