Browse Source

SPR-6502 - Broken @RequestMapping inheritance

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2594 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Arjen Poutsma 16 years ago
parent
commit
6ac29a70e9
  1. 18
      org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java
  2. 51
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java
  3. 4
      org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java

18
org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java

@ -561,7 +561,7 @@ public abstract class ReflectionUtils { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();
}
};
}

51
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

@ -1257,6 +1257,28 @@ public class ServletAnnotationControllerTests { @@ -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 { @@ -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");
}
}
}

4
org.springframework.web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java

@ -87,7 +87,7 @@ public class HandlerMethodResolver { @@ -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 { @@ -99,7 +99,7 @@ public class HandlerMethodResolver {
}
protected boolean isHandlerMethod(Method method) {
return method.isAnnotationPresent(RequestMapping.class);
return AnnotationUtils.findAnnotation(method, RequestMapping.class) != null;
}

Loading…
Cancel
Save