提交 dd2ce206 编写于 作者: J Juergen Hoeller

SpringFactoriesLoader tolerates whitespace around class names

Issue: SPR-17413
上级 83a54dba
...@@ -19,7 +19,6 @@ package org.springframework.core.io.support; ...@@ -19,7 +19,6 @@ package org.springframework.core.io.support;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
...@@ -139,9 +138,10 @@ public final class SpringFactoriesLoader { ...@@ -139,9 +138,10 @@ public final class SpringFactoriesLoader {
UrlResource resource = new UrlResource(url); UrlResource resource = new UrlResource(url);
Properties properties = PropertiesLoaderUtils.loadProperties(resource); Properties properties = PropertiesLoaderUtils.loadProperties(resource);
for (Map.Entry<?, ?> entry : properties.entrySet()) { for (Map.Entry<?, ?> entry : properties.entrySet()) {
List<String> factoryClassNames = Arrays.asList( String factoryClassName = ((String) entry.getKey()).trim();
StringUtils.commaDelimitedListToStringArray((String) entry.getValue())); for (String factoryName : StringUtils.commaDelimitedListToStringArray((String) entry.getValue())) {
result.addAll((String) entry.getKey(), factoryClassNames); result.add(factoryClassName, factoryName.trim());
}
} }
} }
cache.put(classLoader, result); cache.put(classLoader, result);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -33,8 +33,7 @@ public class SpringFactoriesLoaderTests { ...@@ -33,8 +33,7 @@ public class SpringFactoriesLoaderTests {
@Test @Test
public void loadFactoriesInCorrectOrder() { public void loadFactoriesInCorrectOrder() {
List<DummyFactory> factories = SpringFactoriesLoader List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(DummyFactory.class, null);
.loadFactories(DummyFactory.class, null);
assertEquals(2, factories.size()); assertEquals(2, factories.size());
assertTrue(factories.get(0) instanceof MyDummyFactory1); assertTrue(factories.get(0) instanceof MyDummyFactory1);
assertTrue(factories.get(1) instanceof MyDummyFactory2); assertTrue(factories.get(1) instanceof MyDummyFactory2);
...@@ -46,9 +45,9 @@ public class SpringFactoriesLoaderTests { ...@@ -46,9 +45,9 @@ public class SpringFactoriesLoaderTests {
} }
@Test @Test
public void loadPackagePrivateFactory() throws Exception { public void loadPackagePrivateFactory() {
List<DummyPackagePrivateFactory> factories = SpringFactoriesLoader List<DummyPackagePrivateFactory> factories =
.loadFactories(DummyPackagePrivateFactory.class, null); SpringFactoriesLoader.loadFactories(DummyPackagePrivateFactory.class, null);
assertEquals(1, factories.size()); assertEquals(1, factories.size());
assertTrue((factories.get(0).getClass().getModifiers() & Modifier.PUBLIC) == 0); assertTrue((factories.get(0).getClass().getModifiers() & Modifier.PUBLIC) == 0);
} }
......
org.springframework.core.io.support.DummyFactory=\ org.springframework.core.io.support.DummyFactory =\
org.springframework.core.io.support.MyDummyFactory2,\ org.springframework.core.io.support.MyDummyFactory2, \
org.springframework.core.io.support.MyDummyFactory1 org.springframework.core.io.support.MyDummyFactory1
java.lang.String=\ java.lang.String=\
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册