2828
2929import org .apache .commons .logging .Log ;
3030import org .apache .commons .logging .LogFactory ;
31+
3132import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
3233import org .springframework .core .io .UrlResource ;
3334import org .springframework .util .Assert ;
6061 */
6162public abstract class SpringFactoriesLoader {
6263
63- private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
64-
65- private static Map <ClassLoader , MultiValueMap <String , String >> cache = new ConcurrentReferenceHashMap <>();
66-
6764 /**
6865 * The location to look for factories.
6966 * <p>Can be present in multiple JAR files.
7067 */
7168 public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories" ;
7269
7370
71+ private static final Log logger = LogFactory .getLog (SpringFactoriesLoader .class );
72+
73+ private static final Map <ClassLoader , MultiValueMap <String , String >> cache = new ConcurrentReferenceHashMap <>();
74+
75+
7476 /**
7577 * Load and instantiate the factory implementations of the given type from
7678 * {@value #FACTORIES_RESOURCE_LOCATION}, using the given class loader.
77- * <p>The returned factories are sorted in accordance with the {@link AnnotationAwareOrderComparator}.
79+ * <p>The returned factories are sorted through {@link AnnotationAwareOrderComparator}.
7880 * <p>If a custom instantiation strategy is required, use {@link #loadFactoryNames}
7981 * to obtain all registered factory names.
8082 * @param factoryClass the interface or abstract class representing the factory
@@ -113,19 +115,17 @@ public static <T> List<T> loadFactories(Class<T> factoryClass, ClassLoader class
113115 */
114116 public static List <String > loadFactoryNames (Class <?> factoryClass , ClassLoader classLoader ) {
115117 String factoryClassName = factoryClass .getName ();
116- return loadSpringFactories (classLoader ).getOrDefault (factoryClassName ,
117- Collections .emptyList ());
118+ return loadSpringFactories (classLoader ).getOrDefault (factoryClassName , Collections .emptyList ());
118119 }
119120
120- private static Map <String , List <String >> loadSpringFactories (
121- ClassLoader classLoader ) {
121+ private static Map <String , List <String >> loadSpringFactories (ClassLoader classLoader ) {
122122 MultiValueMap <String , String > result = cache .get (classLoader );
123123 if (result != null )
124124 return result ;
125125 try {
126- Enumeration <URL > urls = (classLoader != null
127- ? classLoader .getResources (FACTORIES_RESOURCE_LOCATION )
128- : ClassLoader .getSystemResources (FACTORIES_RESOURCE_LOCATION ));
126+ Enumeration <URL > urls = (classLoader != null ?
127+ classLoader .getResources (FACTORIES_RESOURCE_LOCATION ) :
128+ ClassLoader .getSystemResources (FACTORIES_RESOURCE_LOCATION ));
129129 result = new LinkedMultiValueMap <>();
130130 while (urls .hasMoreElements ()) {
131131 URL url = urls .nextElement ();
@@ -141,8 +141,8 @@ private static Map<String, List<String>> loadSpringFactories(
141141 return result ;
142142 }
143143 catch (IOException ex ) {
144- throw new IllegalArgumentException ("Unable to load factories from location ["
145- + FACTORIES_RESOURCE_LOCATION + "]" , ex );
144+ throw new IllegalArgumentException ("Unable to load factories from location [" +
145+ FACTORIES_RESOURCE_LOCATION + "]" , ex );
146146 }
147147 }
148148
0 commit comments