Skip to content

Commit 75d8311

Browse files
committed
refactor: Remove obsolete SpringFactoriesLoader#loadFactoryNames
1 parent 97cc886 commit 75d8311

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapImportSelector.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.springframework.boot.context.annotation.ImportCandidates;
2728
import org.springframework.context.EnvironmentAware;
2829
import org.springframework.context.annotation.DeferredImportSelector;
2930
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
3031
import org.springframework.core.annotation.Order;
3132
import org.springframework.core.env.Environment;
32-
import org.springframework.core.io.support.SpringFactoriesLoader;
3333
import org.springframework.core.style.ToStringCreator;
3434
import org.springframework.core.type.AnnotationMetadata;
3535
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
@@ -38,9 +38,10 @@
3838
import org.springframework.util.StringUtils;
3939

4040
/**
41-
* This class uses {@link SpringFactoriesLoader} to load {@link BootstrapConfiguration}
42-
* entries from {@code spring.factories}. The classes are then loaded so they can be
43-
* sorted using {@link AnnotationAwareOrderComparator#sort(List)}. This class is a
41+
* This class uses {@link ImportCandidates} to load {@link BootstrapConfiguration} entries
42+
* from {@code org.springframework.cloud.bootstrap.BootstrapConfiguration.imports}.
43+
* The classes are then loaded so they can be sorted using
44+
* {@link AnnotationAwareOrderComparator#sort(List)}. This class is a
4445
* {@link DeferredImportSelector} so {@code @Conditional} annotations on imported classes
4546
* are supported.
4647
*
@@ -62,7 +63,7 @@ public String[] selectImports(AnnotationMetadata annotationMetadata) {
6263
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
6364
// Use names and ensure unique to protect against duplicates
6465
List<String> names = new ArrayList<>(
65-
SpringFactoriesLoader.loadFactoryNames(BootstrapConfiguration.class, classLoader));
66+
ImportCandidates.load(BootstrapConfiguration.class, classLoader).getCandidates());
6667
names.addAll(Arrays.asList(StringUtils
6768
.commaDelimitedListToStringArray(this.environment.getProperty("spring.cloud.bootstrap.sources", ""))));
6869

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

+6-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.boot.SpringApplication;
3030
import org.springframework.boot.env.EnvironmentPostProcessor;
3131
import org.springframework.boot.logging.DeferredLogFactory;
32-
import org.springframework.boot.util.Instantiator;
3332
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
3433
import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
3534
import org.springframework.cloud.context.scope.refresh.RefreshScope;
@@ -77,17 +76,12 @@ protected void updateEnvironment() {
7776
// decrypt happen after refresh. The hard coded call to
7877
// ConfigDataEnvironmentPostProcessor.applyTo() is now automated as well.
7978
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);
79+
SpringFactoriesLoader.ArgumentResolver argumentResolver = SpringFactoriesLoader.ArgumentResolver.of(DeferredLogFactory.class, logFactory);
80+
argumentResolver = argumentResolver.and(ConfigurableBootstrapContext.class, bootstrapContext);
81+
argumentResolver = argumentResolver.and(BootstrapContext.class, bootstrapContext);
82+
argumentResolver = argumentResolver.and(BootstrapRegistry.class, bootstrapContext);
83+
SpringFactoriesLoader loader = SpringFactoriesLoader.forDefaultResourceLocation(getClass().getClassLoader());
84+
List<EnvironmentPostProcessor> postProcessors = loader.load(EnvironmentPostProcessor.class, argumentResolver);
9185
for (EnvironmentPostProcessor postProcessor : postProcessors) {
9286
postProcessor.postProcessEnvironment(environment, application);
9387
}

spring-cloud-context/src/main/resources/META-INF/spring.factories

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ org.springframework.context.ApplicationListener=\
33
org.springframework.cloud.bootstrap.BootstrapApplicationListener,\
44
org.springframework.cloud.bootstrap.LoggingSystemShutdownListener,\
55
org.springframework.cloud.context.restart.RestartListener
6-
# Spring Cloud Bootstrap components
7-
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
8-
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration,\
9-
org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration,\
10-
org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration,\
11-
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
126
# Spring Boot BootstrapRegistryInitializer
137
org.springframework.boot.BootstrapRegistryInitializer=\
148
org.springframework.cloud.bootstrap.RefreshBootstrapRegistryInitializer,\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration
2+
org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration
3+
org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration
4+
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Bootstrap components
2-
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
3-
org.springframework.cloud.bootstrap.TestBootstrapConfiguration,\
4-
org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration
5-
61
org.springframework.boot.env.EnvironmentPostProcessor=\
72
org.springframework.cloud.context.test.TestEnvPostProcessor
83

@@ -12,4 +7,4 @@ org.springframework.cloud.context.test.TestConfigDataLocationResolver
127

138
# ConfigData Loaders
149
org.springframework.boot.context.config.ConfigDataLoader=\
15-
org.springframework.cloud.context.test.TestConfigDataLoader
10+
org.springframework.cloud.context.test.TestConfigDataLoader
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.springframework.cloud.bootstrap.TestBootstrapConfiguration
2+
org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration

0 commit comments

Comments
 (0)