diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java index f71eb5d178f..a0701c2558d 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConstructorArgumentValues.java @@ -76,7 +76,7 @@ public class ConstructorArgumentValues { } for (ValueHolder valueHolder : other.genericArgumentValues) { if (!this.genericArgumentValues.contains(valueHolder)) { - this.genericArgumentValues.add(valueHolder.copy()); + addOrMergeGenericArgumentValue(valueHolder.copy()); } } } @@ -84,7 +84,7 @@ public class ConstructorArgumentValues { /** - * Add argument value for the given index in the constructor argument list. + * Add an argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param value the argument value */ @@ -93,7 +93,7 @@ public class ConstructorArgumentValues { } /** - * Add argument value for the given index in the constructor argument list. + * Add an argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param value the argument value * @param type the type of the constructor argument @@ -103,7 +103,7 @@ public class ConstructorArgumentValues { } /** - * Add argument value for the given index in the constructor argument list. + * Add an argument value for the given index in the constructor argument list. * @param index the index in the constructor argument list * @param newValue the argument value in the form of a ValueHolder */ @@ -114,7 +114,7 @@ public class ConstructorArgumentValues { } /** - * Add argument value for the given index in the constructor argument list, + * Add an argument value for the given index in the constructor argument list, * merging the new value (typically a collection) with the current value * if demanded: see {@link org.springframework.beans.Mergeable}. * @param key the index in the constructor argument list @@ -183,7 +183,7 @@ public class ConstructorArgumentValues { /** - * Add generic argument value to be matched by type. + * Add a generic argument value to be matched by type. *
Note: A single generic argument value will just be used once, * rather than matched multiple times. * @param value the argument value @@ -193,7 +193,7 @@ public class ConstructorArgumentValues { } /** - * Add generic argument value to be matched by type. + * Add a generic argument value to be matched by type. *
Note: A single generic argument value will just be used once, * rather than matched multiple times. * @param value the argument value @@ -204,7 +204,7 @@ public class ConstructorArgumentValues { } /** - * Add generic argument value to be matched by type. + * Add a generic argument value to be matched by type or name (if available). *
Note: A single generic argument value will just be used once,
* rather than matched multiple times.
* @param newValue the argument value in the form of a ValueHolder
@@ -215,10 +215,33 @@ public class ConstructorArgumentValues {
public void addGenericArgumentValue(ValueHolder newValue) {
Assert.notNull(newValue, "ValueHolder must not be null");
if (!this.genericArgumentValues.contains(newValue)) {
- this.genericArgumentValues.add(newValue);
+ addOrMergeGenericArgumentValue(newValue);
}
}
+ /**
+ * Add a generic argument value, merging the new value (typically a collection)
+ * with the current value if demanded: see {@link org.springframework.beans.Mergeable}.
+ * @param newValue the argument value in the form of a ValueHolder
+ */
+ private void addOrMergeGenericArgumentValue(ValueHolder newValue) {
+ if (newValue.getName() != null) {
+ for (Iteratornull to find
* an arbitrary next generic argument value)
- * @param requiredName the type to match (can be null to match
- * unnamed values only)
+ * @param requiredName the name to match (can be null to not
+ * match argument values by name)
* @param usedValueHolders a Set of ValueHolder objects that have already been used
* in the current resolution process and should therefore not be returned again
* @return the ValueHolder for the argument, or null if none found
diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
index 905a4d6e016..bc4f87d63a4 100644
--- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
+++ b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests-constructorArg.xml
@@ -109,7 +109,12 @@