// Already found greedy constructor that can be satisfied ->
// do not look any further, there are only less greedy constructors left.
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 and/or type arguments for simple parameters to avoid type ambiguities)");
}
ArgumentsHolder args = null;
if (resolvedValues != null) {
// Try to resolve arguments for current constructor.
try {
args = createArgumentArray(
beanName, mbd, resolvedValues, bw, paramTypes, candidate, autowiring);
}
catch (UnsatisfiedDependencyException ex) {
if (this.beanFactory.logger.isTraceEnabled()) {
this.beanFactory.logger.trace(
"Ignoring constructor [" + candidate + "] of bean '" + beanName + "': " + ex);
}
if (i == candidates.length - 1 && constructorToUse == null) {
throw ex;
}
else {
// Swallow and try next constructor.
this.beanFactory.onSuppressedException(ex);
continue;
}
}
}
else {
// Explicit arguments given -> arguments length must match exactly.
if (paramTypes.length != explicitArgs.length) {
continue;
}
args = new ArgumentsHolder(explicitArgs);
}
int typeDiffWeight = args.getTypeDifferenceWeight(paramTypes);
// Choose this constructor if it represents the closest match.
if (typeDiffWeight < minTypeDiffWeight) {
constructorToUse = candidate;
argsToUse = args.arguments;
minTypeDiffWeight = typeDiffWeight;
}
}
if (constructorToUse == null) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Could not resolve matching constructor");
}
if (explicitArgs == null) {
mbd.resolvedConstructorOrFactoryMethod = constructorToUse;
}
}
try {
Object beanInstance = this.instantiationStrategy.instantiate(
mbd, beanName, this.beanFactory, constructorToUse, argsToUse);
bw.setWrappedInstance(beanInstance);
return bw;
}
catch (Throwable ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Instantiation of bean failed", ex);
}
}