Skip to content

Commit 44b9a6c

Browse files
committed
Reuse EnvironmentPostProcessorsFactory provided by Spring Boot
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent 7e1cbf8 commit 44b9a6c

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,14 +22,12 @@
2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
2424

25-
import org.springframework.boot.BootstrapContext;
26-
import org.springframework.boot.BootstrapRegistry;
2725
import org.springframework.boot.ConfigurableBootstrapContext;
2826
import org.springframework.boot.DefaultBootstrapContext;
2927
import org.springframework.boot.SpringApplication;
3028
import org.springframework.boot.env.EnvironmentPostProcessor;
29+
import org.springframework.boot.env.EnvironmentPostProcessorsFactory;
3130
import org.springframework.boot.logging.DeferredLogFactory;
32-
import org.springframework.boot.util.Instantiator;
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)