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 197e37a770..adc5079772 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 @@ -19,7 +19,6 @@ package org.springframework.core.io.support; import java.io.IOException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.List; @@ -82,9 +81,9 @@ public abstract class SpringFactoriesLoader { * 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 + * @see #loadFactoryNames */ public static List loadFactories(Class factoryClass, @Nullable ClassLoader classLoader) { Assert.notNull(factoryClass, "'factoryClass' must not be null"); @@ -111,8 +110,8 @@ public abstract class SpringFactoriesLoader { * @param factoryClass the interface or abstract class representing the factory * @param classLoader the ClassLoader to use for loading resources; can be * {@code null} to use the default - * @see #loadFactories * @throws IllegalArgumentException if an error occurs while loading factory names + * @see #loadFactories */ public static List loadFactoryNames(Class factoryClass, @Nullable ClassLoader classLoader) { String factoryClassName = factoryClass.getName(); @@ -135,9 +134,10 @@ public abstract class SpringFactoriesLoader { UrlResource resource = new UrlResource(url); Properties properties = PropertiesLoaderUtils.loadProperties(resource); for (Map.Entry entry : properties.entrySet()) { - List factoryClassNames = Arrays.asList( - StringUtils.commaDelimitedListToStringArray((String) entry.getValue())); - result.addAll((String) entry.getKey(), factoryClassNames); + String factoryClassName = ((String) entry.getKey()).trim(); + for (String factoryName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) { + result.add(factoryClassName, factoryName.trim()); + } } } cache.put(classLoader, result); diff --git a/spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java b/spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java index 4de87d2c72..56939b9cfc 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/SpringFactoriesLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,7 @@ public class SpringFactoriesLoaderTests { @Test public void loadFactoriesInCorrectOrder() { - List factories = SpringFactoriesLoader - .loadFactories(DummyFactory.class, null); + List factories = SpringFactoriesLoader.loadFactories(DummyFactory.class, null); assertEquals(2, factories.size()); assertTrue(factories.get(0) instanceof MyDummyFactory1); assertTrue(factories.get(1) instanceof MyDummyFactory2); @@ -46,9 +45,9 @@ public class SpringFactoriesLoaderTests { } @Test - public void loadPackagePrivateFactory() throws Exception { - List factories = SpringFactoriesLoader - .loadFactories(DummyPackagePrivateFactory.class, null); + public void loadPackagePrivateFactory() { + List factories = + SpringFactoriesLoader.loadFactories(DummyPackagePrivateFactory.class, null); assertEquals(1, factories.size()); assertTrue((factories.get(0).getClass().getModifiers() & Modifier.PUBLIC) == 0); } diff --git a/spring-core/src/test/resources/META-INF/spring.factories b/spring-core/src/test/resources/META-INF/spring.factories index ab64ffe1b6..3c2c4e9d95 100644 --- a/spring-core/src/test/resources/META-INF/spring.factories +++ b/spring-core/src/test/resources/META-INF/spring.factories @@ -1,5 +1,5 @@ -org.springframework.core.io.support.DummyFactory=\ -org.springframework.core.io.support.MyDummyFactory2,\ +org.springframework.core.io.support.DummyFactory =\ +org.springframework.core.io.support.MyDummyFactory2, \ org.springframework.core.io.support.MyDummyFactory1 java.lang.String=\