Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove obsolete SpringFactoriesLoader#loadFactoryNames #1303

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import java.util.List;
import java.util.Map;

import org.springframework.boot.context.annotation.ImportCandidates;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.style.ToStringCreator;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
Expand All @@ -38,9 +38,10 @@
import org.springframework.util.StringUtils;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.DefaultBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.boot.env.EnvironmentPostProcessorsFactory;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.boot.util.Instantiator;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
Expand All @@ -38,7 +36,6 @@
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.support.SpringFactoriesLoader;

/**
* @author Dave Syer
Expand Down Expand Up @@ -77,17 +74,8 @@ protected void updateEnvironment() {
// decrypt happen after refresh. The hard coded call to
// ConfigDataEnvironmentPostProcessor.applyTo() is now automated as well.
DeferredLogFactory logFactory = new PassthruDeferredLogFactory();
List<String> classNames = SpringFactoriesLoader.loadFactoryNames(EnvironmentPostProcessor.class,
getClass().getClassLoader());
Instantiator<EnvironmentPostProcessor> instantiator = new Instantiator<>(EnvironmentPostProcessor.class,
(parameters) -> {
parameters.add(DeferredLogFactory.class, logFactory);
parameters.add(Log.class, logFactory::getLog);
parameters.add(ConfigurableBootstrapContext.class, bootstrapContext);
parameters.add(BootstrapContext.class, bootstrapContext);
parameters.add(BootstrapRegistry.class, bootstrapContext);
});
List<EnvironmentPostProcessor> postProcessors = instantiator.instantiate(classNames);
EnvironmentPostProcessorsFactory environmentPostProcessorsFactory = EnvironmentPostProcessorsFactory.fromSpringFactories(getClass().getClassLoader());
List<EnvironmentPostProcessor> postProcessors = environmentPostProcessorsFactory.getEnvironmentPostProcessors(logFactory, bootstrapContext);
for (EnvironmentPostProcessor postProcessor : postProcessors) {
postProcessor.postProcessEnvironment(environment, application);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ org.springframework.context.ApplicationListener=\
org.springframework.cloud.bootstrap.BootstrapApplicationListener,\
org.springframework.cloud.bootstrap.LoggingSystemShutdownListener,\
org.springframework.cloud.context.restart.RestartListener
# Spring Cloud Bootstrap components
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration,\
org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration,\
org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration,\
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
# Spring Boot BootstrapRegistryInitializer
org.springframework.boot.BootstrapRegistryInitializer=\
org.springframework.cloud.bootstrap.RefreshBootstrapRegistryInitializer,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration
org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration
org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Bootstrap components
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.bootstrap.TestBootstrapConfiguration,\
org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration

org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.context.test.TestEnvPostProcessor

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

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