57
57
*/
58
58
public abstract class SpringFactoriesLoader {
59
59
60
- private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
61
-
62
60
/**
63
61
* The location to look for factories.
64
62
* <p>Can be present in multiple JAR files.
65
63
*/
66
64
public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories" ;
67
65
66
+ private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
67
+
68
68
69
69
/**
70
70
* Load and instantiate the factory implementations of the given type from
@@ -74,9 +74,9 @@ public abstract class SpringFactoriesLoader {
74
74
* to obtain all registered factory names.
75
75
* @param factoryClass the interface or abstract class representing the factory
76
76
* @param classLoader the ClassLoader to use for loading (can be {@code null} to use the default)
77
- * @see #loadFactoryNames
78
77
* @throws IllegalArgumentException if any factory implementation class cannot
79
78
* be loaded or if an error occurs while instantiating any factory
79
+ * @see #loadFactoryNames
80
80
*/
81
81
public static <T > List <T > loadFactories (Class <T > factoryClass , ClassLoader classLoader ) {
82
82
Assert .notNull (factoryClass , "'factoryClass' must not be null" );
@@ -103,8 +103,8 @@ public static <T> List<T> loadFactories(Class<T> factoryClass, ClassLoader class
103
103
* @param factoryClass the interface or abstract class representing the factory
104
104
* @param classLoader the ClassLoader to use for loading resources; can be
105
105
* {@code null} to use the default
106
- * @see #loadFactories
107
106
* @throws IllegalArgumentException if an error occurs while loading factory names
107
+ * @see #loadFactories
108
108
*/
109
109
public static List <String > loadFactoryNames (Class <?> factoryClass , ClassLoader classLoader ) {
110
110
String factoryClassName = factoryClass .getName ();
@@ -115,14 +115,16 @@ public static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader c
115
115
while (urls .hasMoreElements ()) {
116
116
URL url = urls .nextElement ();
117
117
Properties properties = PropertiesLoaderUtils .loadProperties (new UrlResource (url ));
118
- String factoryClassNames = properties .getProperty (factoryClassName );
119
- result .addAll (Arrays .asList (StringUtils .commaDelimitedListToStringArray (factoryClassNames )));
118
+ String propertyValue = properties .getProperty (factoryClassName );
119
+ for (String factoryName : StringUtils .commaDelimitedListToStringArray (propertyValue )) {
120
+ result .add (factoryName .trim ());
121
+ }
120
122
}
121
123
return result ;
122
124
}
123
125
catch (IOException ex ) {
124
- throw new IllegalArgumentException ("Unable to load [" + factoryClass . getName () +
125
- "] factories from location [" + FACTORIES_RESOURCE_LOCATION + "]" , ex );
126
+ throw new IllegalArgumentException ("Unable to load factories from location [" +
127
+ FACTORIES_RESOURCE_LOCATION + "]" , ex );
126
128
}
127
129
}
128
130
0 commit comments