Class SpringFactoriesLoader
- java.lang.Object
- org.springframework.core.io.support.SpringFactoriesLoader
public final class SpringFactoriesLoader extends Object
General purpose factory loading mechanism for internal use within the framework.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. Thespring.factories
file must be inProperties
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.MyServiceImpl2
whereexample.MyService
is the name of the interface, andMyServiceImpl1
andMyServiceImpl2
are two implementations.- Since:
- 3.2
- Author:
- Arjen Poutsma, Juergen Hoeller, Sam Brannen
Field Summary
Fields Modifier and Type Field Description static String
FACTORIES_RESOURCE_LOCATION
The location to look for factories.
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<T>
loadFactories(Class<T> factoryType, ClassLoader classLoader)
Load and instantiate the factory implementations of the given type from "META-INF/spring.factories", using the given class loader.static List<String>
loadFactoryNames(Class<?> factoryType, ClassLoader classLoader)
Load the fully qualified class names of factory implementations of the given type from "META-INF/spring.factories", using the given class loader.
Field Detail
FACTORIES_RESOURCE_LOCATION
public static final String FACTORIES_RESOURCE_LOCATION
The location to look for factories.Can be present in multiple JAR files.
- See Also:
- Constant Field Values
Method Detail
loadFactories
public static <T> List<T> loadFactories(Class<T> factoryType, @Nullable ClassLoader classLoader)
Load and instantiate the factory implementations of the given type from "META-INF/spring.factories", using the given class loader.The returned factories are sorted through
AnnotationAwareOrderComparator
.If a custom instantiation strategy is required, use
loadFactoryNames(java.lang.Class<?>, java.lang.ClassLoader)
to obtain all registered factory names.- Parameters:
factoryType
- the interface or abstract class representing the factoryclassLoader
- the ClassLoader to use for loading (can benull
to use the default)- Throws:
IllegalArgumentException
- if any factory implementation class cannot be loaded or if an error occurs while instantiating any factory- See Also:
loadFactoryNames(java.lang.Class<?>, java.lang.ClassLoader)
loadFactoryNames
public static List<String> loadFactoryNames(Class<?> factoryType, @Nullable ClassLoader classLoader)
Load the fully qualified class names of factory implementations of the given type from "META-INF/spring.factories", using the given class loader.- Parameters:
factoryType
- the interface or abstract class representing the factoryclassLoader
- the ClassLoader to use for loading resources; can benull
to use the default- Throws:
IllegalArgumentException
- if an error occurs while loading factory names- See Also:
loadFactories(java.lang.Class<T>, java.lang.ClassLoader)