Class SpringFactoriesLoader

Direct Known Subclasses:

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:

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.

Arjen Poutsma, Juergen Hoeller, Sam Brannen, Andy Wilkinson, Madhura Bhave, Phillip Webb