|
24 | 24 |
|
25 | 25 | import org.springframework.boot.EnvironmentPostProcessor;
|
26 | 26 | import org.springframework.boot.SpringApplication;
|
27 |
| -import org.springframework.boot.bootstrap.BootstrapContext; |
28 |
| -import org.springframework.boot.bootstrap.BootstrapRegistry; |
29 | 27 | import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
|
30 | 28 | 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; |
31 | 34 | import org.springframework.boot.logging.DeferredLogFactory;
|
32 |
| -import org.springframework.boot.util.Instantiator; |
33 | 35 | import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
|
34 | 36 | import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
|
35 | 37 | import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
|
38 | 40 | import org.springframework.core.env.MutablePropertySources;
|
39 | 41 | import org.springframework.core.env.PropertySource;
|
40 | 42 | import org.springframework.core.env.StandardEnvironment;
|
41 |
| -import org.springframework.core.io.support.SpringFactoriesLoader; |
42 | 43 |
|
43 | 44 | /**
|
44 | 45 | * @author Dave Syer
|
45 | 46 | * @author Venil Noronha
|
| 47 | + * @author Yanming Zhou |
46 | 48 | */
|
47 | 49 | public class ConfigDataContextRefresher extends ContextRefresher
|
48 | 50 | implements ApplicationListener<ContextRefreshedWithApplicationEvent> {
|
@@ -77,17 +79,10 @@ protected void updateEnvironment() {
|
77 | 79 | // decrypt happen after refresh. The hard coded call to
|
78 | 80 | // ConfigDataEnvironmentPostProcessor.applyTo() is now automated as well.
|
79 | 81 | 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); |
91 | 86 | for (EnvironmentPostProcessor postProcessor : postProcessors) {
|
92 | 87 | postProcessor.postProcessEnvironment(environment, application);
|
93 | 88 | }
|
|
0 commit comments