Class SpringFactoriesLoader

java.lang.Object
org.springframework.core.io.support.SpringFactoriesLoader
Direct Known Subclasses:
MockSpringFactoriesLoader

public 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. 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.MyServiceImpl2
where 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:

  • a primary or single constructor
  • a single public constructor
  • the default constructor

If the resolvable constructor has arguments, a suitable ArgumentResolver should be provided. To customize how instantiation failures are handled, consider providing a FailureHandler.

Since:
3.2
Author:
Arjen Poutsma, Juergen Hoeller, Sam Brannen, Andy Wilkinson, Madhura Bhave, Phillip Webb
  • Field Details

    • 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:
  • Constructor Details

    • SpringFactoriesLoader

      protected SpringFactoriesLoader(@Nullable ClassLoader classLoader, Map<String,List<String>> factories)
      Create a new SpringFactoriesLoader instance.
      Parameters:
      classLoader - the classloader used to instantiate the factories
      factories - a map of factory class name to implementation class names
      Since:
      6.0
  • Method Details