diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java index abdfa341809..cb1bce28eee 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java @@ -43,8 +43,8 @@ import org.springframework.util.ClassUtils; abstract class AutowireUtils { /** - * Sort the given constructors, preferring public constructors and "greedy" ones - * with a maximum of arguments. The result will contain public constructors first, + * Sort the given constructors, preferring public constructors and "greedy" ones with + * a maximum number of arguments. The result will contain public constructors first, * with decreasing number of arguments, then non-public constructors, again with * decreasing number of arguments. * @param constructors the constructor array to sort diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index be5ab01d5d7..84052539489 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -172,10 +172,7 @@ class ConstructorResolver { break; } if (paramTypes.length < minNrOfArgs) { - throw new BeanCreationException(mbd.getResourceDescription(), beanName, - minNrOfArgs + " constructor arguments specified but no matching constructor found in bean '" + - beanName + "' " + - "(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)"); + continue; } ArgumentsHolder argsHolder; @@ -245,8 +242,9 @@ class ConstructorResolver { } if (constructorToUse == null) { - throw new BeanCreationException( - mbd.getResourceDescription(), beanName, "Could not resolve matching constructor"); + throw new BeanCreationException(mbd.getResourceDescription(), beanName, + "Could not resolve matching constructor " + + "(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)"); } else if (ambiguousConstructors != null && !mbd.isLenientConstructorResolution()) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, @@ -663,16 +661,16 @@ class ConstructorResolver { // We found a potential match - let's give it a try. // Do not consider the same value definition multiple times! usedValueHolders.add(valueHolder); - ConstructorArgumentValues.ValueHolder sourceHolder = - (ConstructorArgumentValues.ValueHolder) valueHolder.getSource(); Object originalValue = valueHolder.getValue(); - Object sourceValue = sourceHolder.getValue(); Object convertedValue; if (valueHolder.isConverted()) { convertedValue = valueHolder.getConvertedValue(); args.preparedArguments[paramIndex] = convertedValue; } else { + ConstructorArgumentValues.ValueHolder sourceHolder = + (ConstructorArgumentValues.ValueHolder) valueHolder.getSource(); + Object sourceValue = sourceHolder.getValue(); try { convertedValue = converter.convertIfNecessary(originalValue, paramType, MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex)); diff --git a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java index c76f8892774..2c18eb99648 100644 --- a/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java +++ b/org.springframework.context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java @@ -738,7 +738,7 @@ class SingleSimpleTypeConstructorBean { this.singleBoolean = singleBoolean; } - public SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) { + protected SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) { this.testString = testString; this.secondBoolean = secondBoolean; }