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