SpringFactoriesLoader loads and instantiates
factories of a given type from META-INF/spring.factories files which
may be present in multiple JAR files in the classpath. The spring.factories
file must be in Properties format, where the key is the fully qualified
name of the interface or abstract class, and the value is a comma-separated list of
implementation class names. For example:
example.MyService=example.MyServiceImpl1,example.MyServiceImpl2where
example.MyService is the name of the interface, and MyServiceImpl1
and MyServiceImpl2 are two implementations.
Implementation classes must have a single resolvable constructor that will be used to create the instance, either:
If the resolvable constructor has arguments, a suitable ArgumentResolver should be provided. To customize how instantiation failures
are handled, consider providing a FailureHandler.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | SpringFactoriesLoader.
Strategy for resolving constructor arguments based on their type. |
| pack-priv static class | SpringFactoriesLoader.
the instance implementation type T>Internal instantiator used to create the factory instance. |
| public static interface | SpringFactoriesLoader.
Strategy for handling a failure that occurs when instantiating a factory. |
| private static class | SpringFactoriesLoader.
Nested class to avoid a hard dependency on Kotlin at runtime. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Map | |
| private final ClassLoader | |
| private final Map | |
| public static final String | FACTORIES_RESOURCE_LOCATION
The location to look for factories. |
| private static final Log | |
| private static final SpringFactoriesLoader. |
| Access | Constructor and Description |
|---|---|
| protected | SpringFactoriesLoader(ClassLoader
the classloader used to instantiate the factories classLoader, Map<String, List<String>> a map of factory class name to implementation class names factories)Create a new |
| Modifier and Type | Method and Description |
|---|---|
| public static SpringFactoriesLoader | Returns: aSpringFactoriesLoader instanceCreate a |
| public static SpringFactoriesLoader | Returns: aSpringFactoriesLoader instancethe ClassLoader to use for loading resources; can be
classLoader)null to use the defaultCreate a |
| public static SpringFactoriesLoader | Returns: aSpringFactoriesLoader instancethe resource location to look for factories resourceLocation)Create a |
| public static SpringFactoriesLoader | Returns: aSpringFactoriesLoader instancethe resource location to look for factories resourceLocation, ClassLoader the ClassLoader to use for loading resources;
can be classLoader)null to use the defaultCreate a |
| protected <T> T | instantiateFactory(String implementationName, Class<T> type, SpringFactoriesLoader.
|
| public <T> List | |
| public <T> List | load(Class<T>
the interface or abstract class representing the factory factoryType, SpringFactoriesLoader.strategy used to resolve constructor arguments by their type argumentResolverLoad and instantiate the factory implementations of the given type from META-INF/spring.factories, using the configured class loader and the given argument resolver. |
| public <T> List | load(Class<T>
the interface or abstract class representing the factory factoryType, SpringFactoriesLoader.strategy used to handle factory instantiation failures failureHandlerLoad and instantiate the factory implementations of the given type from META-INF/spring.factories, using the configured class loader with custom failure handling provided by the given failure handler. |
| public <T> List | load(Class<T>
the interface or abstract class representing the factory factoryType, SpringFactoriesLoader.strategy used to resolve constructor arguments by their type argumentResolver,strategy used to handle factory instantiation failures failureHandlerLoad and instantiate the factory implementations of the given type from META-INF/spring.factories, using the configured class loader, the given argument resolver, and custom failure handling provided by the given failure handler. |
| public static <T> List | loadFactories(Class<T>
the interface or abstract class representing the factory factoryType, ClassLoader the ClassLoader to use for loading (can be classLoader)null
to use the default)Load and instantiate the factory implementations of the given type from META-INF/spring.factories, using the given class loader. |
| protected static Map | |
| private List | |
| public static List | loadFactoryNames(Class<?>
the interface or abstract class representing the factory factoryType, ClassLoader the ClassLoader to use for loading resources; can be
classLoader)null to use the default
Deprecated
since 6.0. as of 6.0 in favor of
load(Class, ArgumentResolver, FailureHandler)
Load the fully qualified class names of factory implementations of the given type from META-INF/spring.factories, using the given class loader. |
| private static List |