Spring's constructor resolution consistently finds non-public multi-arg constructors (SPR-7453)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3565 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-08-11 19:24:30 +00:00
parent 2dccb96f85
commit 4e33c7d442
3 changed files with 10 additions and 12 deletions

View File

@ -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

View File

@ -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));

View File

@ -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;
}