|
1 | 1 | /* |
2 | | - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
22 | 22 | import org.apache.commons.logging.Log; |
23 | 23 | import org.apache.commons.logging.LogFactory; |
24 | 24 |
|
25 | | -import org.springframework.boot.BootstrapContext; |
26 | | -import org.springframework.boot.BootstrapRegistry; |
27 | 25 | import org.springframework.boot.ConfigurableBootstrapContext; |
28 | 26 | import org.springframework.boot.DefaultBootstrapContext; |
29 | 27 | import org.springframework.boot.SpringApplication; |
30 | 28 | import org.springframework.boot.env.EnvironmentPostProcessor; |
| 29 | +import org.springframework.boot.env.EnvironmentPostProcessorsFactory; |
31 | 30 | import org.springframework.boot.logging.DeferredLogFactory; |
32 | | -import org.springframework.boot.util.Instantiator; |
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