diff --git a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java index 170c948f940..13b2beea7f3 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -561,7 +561,7 @@ public abstract class ReflectionUtils { /** * Action to take on each method. */ - public static interface MethodCallback { + public interface MethodCallback { /** * Perform an operation using the given method. @@ -574,7 +574,7 @@ public abstract class ReflectionUtils { /** * Callback optionally used to method fields to be operated on by a method callback. */ - public static interface MethodFilter { + public interface MethodFilter { /** * Determine whether the given method matches. @@ -586,7 +586,7 @@ public abstract class ReflectionUtils { /** * Callback interface invoked on each field in the hierarchy. */ - public static interface FieldCallback { + public interface FieldCallback { /** * Perform an operation using the given field. @@ -599,7 +599,7 @@ public abstract class ReflectionUtils { /** * Callback optionally used to filter fields to be operated on by a field callback. */ - public static interface FieldFilter { + public interface FieldFilter { /** * Determine whether the given field matches. @@ -619,4 +619,14 @@ public abstract class ReflectionUtils { } }; + /** + * Pre-built MethodFilter that matches all non-bridge methods. + */ + public static MethodFilter NON_BRIDGED_METHODS = new MethodFilter() { + + public boolean matches(Method method) { + return !method.isBridge(); + } + }; + } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java index 25d06cdae35..9559476e9a4 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java @@ -1257,6 +1257,28 @@ public class ServletAnnotationControllerTests { assertEquals("create", response.getContentAsString()); } + @Test + public void requestMappingInterface() throws Exception { + initServlet(IMyControllerImpl.class); + + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle"); + MockHttpServletResponse response = new MockHttpServletResponse(); + servlet.service(request, response); + assertEquals("handle", response.getContentAsString()); + + } + + @Test + public void requestMappingBaseClass() throws Exception { + initServlet(MyAbstractControllerImpl.class); + + MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle"); + MockHttpServletResponse response = new MockHttpServletResponse(); + servlet.service(request, response); + assertEquals("handle", response.getContentAsString()); + + } + /* * Controllers */ @@ -2140,5 +2162,34 @@ public class ServletAnnotationControllerTests { } + public interface IMyController { + + @RequestMapping("/handle") + void handle(Writer writer) throws IOException; + } + + @Controller + public static class IMyControllerImpl implements IMyController { + + public void handle(Writer writer) throws IOException { + writer.write("handle"); + } + } + + public static abstract class MyAbstractController { + + @RequestMapping("/handle") + public abstract void handle(Writer writer) throws IOException; + } + + @Controller + public static class MyAbstractControllerImpl extends MyAbstractController { + + @Override + public void handle(Writer writer) throws IOException { + writer.write("handle"); + } + } + } 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 816dd4b8067..861d5e753f3 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 @@ -87,7 +87,7 @@ public class HandlerMethodResolver { modelAttributeMethods.add(specificMethod); } } - }); + }, ReflectionUtils.NON_BRIDGED_METHODS); } this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class); SessionAttributes sessionAttributes = handlerType.getAnnotation(SessionAttributes.class); @@ -99,7 +99,7 @@ public class HandlerMethodResolver { } protected boolean isHandlerMethod(Method method) { - return method.isAnnotationPresent(RequestMapping.class); + return AnnotationUtils.findAnnotation(method, RequestMapping.class) != null; }