Hi
I was playing with My First SpringMVC based app..... (3.0.2.RELEASE)
I noticed that AnnotationMethodHandlerAdapter invokes constructor of ServletHandlerMethodResolver, and this constructor invokes init() method of HandlerMethodResolver.
public void init(Class<?> handlerType) {
Class<?>[] handlerTypes =
Proxy.isProxyClass(handlerType) ? handlerType.getInterfaces() : new Class<?>[] {handlerType};
for (final Class<?> currentHandlerType : handlerTypes) {
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, currentHandlerType);
if (isHandlerMethod(method)) {
handlerMethods.add(specificMethod);
}
else if (method.isAnnotationPresent(InitBinder.class)) {
initBinderMethods.add(specificMethod);
}
else if (method.isAnnotationPresent(ModelAttribute.class)) {
modelAttributeMethods.add(specificMethod);
}
}
}, ReflectionUtils.NON_BRIDGED_METHODS);
}
Note: In my case, Proxy.isProxyClass(handlerType) returns false.
This init() method (with help of ReflectionUtils.doWithMethods()) finds @RequestMapping, @InitBinder and @ModelAttribute annotations on the methods of - specified class AND - all of its SuperClasses including Object Class!!!
We should not (and cannot) "put" such annotations on methods of Object class. So, why init() scans the methods of Object class? Please clarify!
- SE