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:
parent
2dccb96f85
commit
4e33c7d442
|
|
@ -43,8 +43,8 @@ import org.springframework.util.ClassUtils;
|
||||||
abstract class AutowireUtils {
|
abstract class AutowireUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the given constructors, preferring public constructors and "greedy" ones
|
* Sort the given constructors, preferring public constructors and "greedy" ones with
|
||||||
* with a maximum of arguments. The result will contain public constructors first,
|
* a maximum number of arguments. The result will contain public constructors first,
|
||||||
* with decreasing number of arguments, then non-public constructors, again with
|
* with decreasing number of arguments, then non-public constructors, again with
|
||||||
* decreasing number of arguments.
|
* decreasing number of arguments.
|
||||||
* @param constructors the constructor array to sort
|
* @param constructors the constructor array to sort
|
||||||
|
|
|
||||||
|
|
@ -172,10 +172,7 @@ class ConstructorResolver {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (paramTypes.length < minNrOfArgs) {
|
if (paramTypes.length < minNrOfArgs) {
|
||||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
continue;
|
||||||
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)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArgumentsHolder argsHolder;
|
ArgumentsHolder argsHolder;
|
||||||
|
|
@ -245,8 +242,9 @@ class ConstructorResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constructorToUse == null) {
|
if (constructorToUse == null) {
|
||||||
throw new BeanCreationException(
|
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||||
mbd.getResourceDescription(), beanName, "Could not resolve matching constructor");
|
"Could not resolve matching constructor " +
|
||||||
|
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)");
|
||||||
}
|
}
|
||||||
else if (ambiguousConstructors != null && !mbd.isLenientConstructorResolution()) {
|
else if (ambiguousConstructors != null && !mbd.isLenientConstructorResolution()) {
|
||||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||||
|
|
@ -663,16 +661,16 @@ class ConstructorResolver {
|
||||||
// We found a potential match - let's give it a try.
|
// We found a potential match - let's give it a try.
|
||||||
// Do not consider the same value definition multiple times!
|
// Do not consider the same value definition multiple times!
|
||||||
usedValueHolders.add(valueHolder);
|
usedValueHolders.add(valueHolder);
|
||||||
ConstructorArgumentValues.ValueHolder sourceHolder =
|
|
||||||
(ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
|
|
||||||
Object originalValue = valueHolder.getValue();
|
Object originalValue = valueHolder.getValue();
|
||||||
Object sourceValue = sourceHolder.getValue();
|
|
||||||
Object convertedValue;
|
Object convertedValue;
|
||||||
if (valueHolder.isConverted()) {
|
if (valueHolder.isConverted()) {
|
||||||
convertedValue = valueHolder.getConvertedValue();
|
convertedValue = valueHolder.getConvertedValue();
|
||||||
args.preparedArguments[paramIndex] = convertedValue;
|
args.preparedArguments[paramIndex] = convertedValue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ConstructorArgumentValues.ValueHolder sourceHolder =
|
||||||
|
(ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
|
||||||
|
Object sourceValue = sourceHolder.getValue();
|
||||||
try {
|
try {
|
||||||
convertedValue = converter.convertIfNecessary(originalValue, paramType,
|
convertedValue = converter.convertIfNecessary(originalValue, paramType,
|
||||||
MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex));
|
MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex));
|
||||||
|
|
|
||||||
|
|
@ -738,7 +738,7 @@ class SingleSimpleTypeConstructorBean {
|
||||||
this.singleBoolean = singleBoolean;
|
this.singleBoolean = singleBoolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) {
|
protected SingleSimpleTypeConstructorBean(String testString, boolean secondBoolean) {
|
||||||
this.testString = testString;
|
this.testString = testString;
|
||||||
this.secondBoolean = secondBoolean;
|
this.secondBoolean = secondBoolean;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue