Allow for specific instance-based match to override factory method signature match

Issue: SPR-11046
This commit is contained in:
Juergen Hoeller
2013-10-30 22:01:32 +01:00
parent ac7e27b785
commit f9584184ef
2 changed files with 122 additions and 21 deletions

View File

@@ -87,7 +87,12 @@ public class GenericTypeAwareAutowireCandidateResolver implements AutowireCandid
else {
Method resolvedFactoryMethod = rbd.getResolvedFactoryMethod();
if (resolvedFactoryMethod != null) {
targetType = ResolvableType.forMethodReturnType(resolvedFactoryMethod);
if (descriptor.getDependencyType().isAssignableFrom(resolvedFactoryMethod.getReturnType())) {
// Only use factory method metadata if the return type is actually expressive enough
// for our dependency. Otherwise, the returned instance type may have matched instead
// in case of a singleton instance having been registered with the container already.
targetType = ResolvableType.forMethodReturnType(resolvedFactoryMethod);
}
}
}
}