protected @Autowired method can be overridden with non-annotated method to suppress injection; private @Autowired methods with same signature will be called individually across a hierarchy (SPR-6112)

This commit is contained in:
Juergen Hoeller
2009-09-15 15:52:13 +00:00
parent fa2bb722f0
commit fd81aa205d
3 changed files with 65 additions and 17 deletions

View File

@@ -689,16 +689,18 @@ public abstract class ClassUtils {
* <code>targetClass</code> doesn't implement it or is <code>null</code>
*/
public static Method getMostSpecificMethod(Method method, Class targetClass) {
if (method != null && targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
Method result = method;
if (method != null && !Modifier.isPrivate(method.getModifiers()) &&
targetClass != null && !targetClass.equals(method.getDeclaringClass())) {
try {
method = targetClass.getMethod(method.getName(), method.getParameterTypes());
result = targetClass.getDeclaredMethod(method.getName(), method.getParameterTypes());
}
catch (NoSuchMethodException ex) {
// Perhaps the target class doesn't implement this method:
// that's fine, just use the original method.
}
}
return method;
return result;
}
/**