diff --git a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java index d6eeabf7e90..d47724994c7 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/SpringFactoriesLoader.java @@ -36,15 +36,17 @@ import org.springframework.util.StringUtils; /** * General purpose factory loading mechanism for internal use within the framework. * - *
The {@code SpringFactoriesLoader} loads and instantiates factories of a given type - * from "META-INF/spring.factories" files. The file should be in {@link Properties} format, - * where the key is the fully qualified interface or abstract class name, and the value - * is a comma-separated list of implementation class names. For instance: + *
{@code SpringFactoriesLoader} {@linkplain #loadFactories loads} and instantiates + * factories of a given type from {@value #FACTORIES_RESOURCE_LOCATION} files which + * may be present in multiple JAR files in the classpath. The {@code spring.factories} + * file must be in {@link 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 {@code MyService} is the name of the interface, and {@code MyServiceImpl1} and - * {@code MyServiceImpl2} are the two implementations. + * where {@code example.MyService} is the name of the interface, and {@code MyServiceImpl1} + * and {@code MyServiceImpl2} are two implementations. * * @author Arjen Poutsma * @author Juergen Hoeller @@ -53,18 +55,26 @@ import org.springframework.util.StringUtils; */ public abstract class SpringFactoriesLoader { - /** The location to look for the factories. Can be present in multiple JAR files. */ - public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories"; - private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class); + /** + * The location to look for factories. + *
Can be present in multiple JAR files. + */ + public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories"; + /** - * Load the factory implementations of the given type from the default location, - * using the given class loader. - *
The returned factories are ordered in accordance with the {@link AnnotationAwareOrderComparator}. + * Load and instantiate the factory implementations of the given type from + * {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader. + *
The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}. + *
If a custom instantiation strategy is required, use {@link #loadFactoryNames}
+ * to obtain all registered factory names.
* @param factoryClass the interface or abstract class representing the factory
* @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default)
+ * @see #loadFactoryNames
+ * @throws IllegalArgumentException if any factory implementation class cannot
+ * be loaded or if an error occurs while instantiating any factory
*/
public static