Skip to content

Commit 18bd4a8

Browse files
committed
improved "no matching factory method found" exception message (SPR-6837)
1 parent 97059f4 commit 18bd4a8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,14 +484,14 @@ public Method[] run() {
484484
factoryMethodToUse = candidate;
485485
argsToUse = args.arguments;
486486
minTypeDiffWeight = typeDiffWeight;
487-
ambiguousFactoryMethods = null;
487+
ambiguousFactoryMethods = null;
488488
}
489489
else if (factoryMethodToUse != null && typeDiffWeight == minTypeDiffWeight) {
490-
if ( ambiguousFactoryMethods == null) {
491-
ambiguousFactoryMethods = new LinkedHashSet<Method>();
492-
ambiguousFactoryMethods.add(factoryMethodToUse);
490+
if (ambiguousFactoryMethods == null) {
491+
ambiguousFactoryMethods = new LinkedHashSet<Method>();
492+
ambiguousFactoryMethods.add(factoryMethodToUse);
493493
}
494-
ambiguousFactoryMethods.add(candidate);
494+
ambiguousFactoryMethods.add(candidate);
495495
}
496496
}
497497
}
@@ -501,7 +501,9 @@ else if (factoryMethodToUse != null && typeDiffWeight == minTypeDiffWeight) {
501501
"No matching factory method found: " +
502502
(mbd.getFactoryBeanName() != null ?
503503
"factory bean '" + mbd.getFactoryBeanName() + "'; " : "") +
504-
"factory method '" + mbd.getFactoryMethodName() + "'");
504+
"factory method '" + mbd.getFactoryMethodName() + "'. " +
505+
"Check that a method of the specified name exists and that it is " +
506+
(isStatic ? "static" : "non-static") + ".");
505507
}
506508
else if (void.class.equals(factoryMethodToUse.getReturnType())) {
507509
throw new BeanCreationException(mbd.getResourceDescription(), beanName,

0 commit comments

Comments
 (0)