SPR-6502 - Broken @RequestMapping inheritance

This commit is contained in:
Arjen Poutsma 2009-12-07 16:44:51 +00:00
parent 09a55c8ede
commit 27e0642543
3 changed files with 67 additions and 6 deletions

View File

@ -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();
}
};
}

View File

@ -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");
}
}
}

View File

@ -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;
}