diff --git a/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java index d0bea4da82..dd22122704 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ClassUtils.java @@ -689,18 +689,12 @@ public abstract class ClassUtils { * targetClass doesn't implement it or is null */ public static Method getMostSpecificMethod(Method method, Class targetClass) { - Method result = method; + Method specificMethod = null; if (method != null && !Modifier.isPrivate(method.getModifiers()) && targetClass != null && !targetClass.equals(method.getDeclaringClass())) { - try { - 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. - } + specificMethod = ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes()); } - return result; + return (specificMethod != null ? specificMethod : method); } /** @@ -716,14 +710,11 @@ public abstract class ClassUtils { Assert.notNull(methodName, "Method name must not be null"); try { Method method = clazz.getDeclaredMethod(methodName, args); - if ((method.getModifiers() & Modifier.STATIC) != 0) { - return method; - } + return ((method.getModifiers() & Modifier.STATIC) != 0 ? method : null); } catch (NoSuchMethodException ex) { return null; } - return null; } diff --git a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java index 5071031d4d..e15350b2b0 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java +++ b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java @@ -72,18 +72,19 @@ public class HandlerMethodResolver { */ public void init(Class handlerType) { Class[] handlerTypes = - Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class[]{handlerType}; + Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class[] {handlerType}; for (final Class currentHandlerType : handlerTypes) { ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() { public void doWith(Method method) { - if (isHandlerMethod(ClassUtils.getMostSpecificMethod(method, currentHandlerType))) { - handlerMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType)); + Method specificMethod = ClassUtils.getMostSpecificMethod(method, currentHandlerType); + if (isHandlerMethod(specificMethod)) { + handlerMethods.add(specificMethod); } else if (method.isAnnotationPresent(InitBinder.class)) { - initBinderMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType)); + initBinderMethods.add(specificMethod); } else if (method.isAnnotationPresent(ModelAttribute.class)) { - modelAttributeMethods.add(ClassUtils.getMostSpecificMethod(method, currentHandlerType)); + modelAttributeMethods.add(specificMethod); } } });