diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java index e4e563c56e5..3b76a9a33dc 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java @@ -44,6 +44,7 @@ import javax.portlet.WindowState; import org.springframework.core.ExceptionDepthComparator; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; +import org.springframework.core.annotation.AnnotationUtils; import org.springframework.ui.Model; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -136,10 +137,11 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc } else { Method oldMappedMethod = resolverMethods.get(handledException); - throw new IllegalStateException( - "Ambiguous exception handler mapped for " + handledException + "]: {" + - oldMappedMethod + ", " + method + "}."); - + if (!oldMappedMethod.equals(method)) { + throw new IllegalStateException( + "Ambiguous exception handler mapped for " + handledException + "]: {" + + oldMappedMethod + ", " + method + "}."); + } } } } @@ -160,7 +162,7 @@ public class AnnotationMethodHandlerExceptionResolver extends AbstractHandlerExc @SuppressWarnings("unchecked") protected List> getHandledExceptions(Method method) { List> result = new ArrayList>(); - ExceptionHandler exceptionHandler = method.getAnnotation(ExceptionHandler.class); + ExceptionHandler exceptionHandler = AnnotationUtils.findAnnotation(method, ExceptionHandler.class); if (exceptionHandler != null) { if (!ObjectUtils.isEmpty(exceptionHandler.value())) { result.addAll(Arrays.asList(exceptionHandler.value())); diff --git a/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java b/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java index 43b4642882b..4dfe1f8681a 100644 --- a/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java +++ b/org.springframework.web.portlet/src/test/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java @@ -90,6 +90,15 @@ public class AnnotationMethodHandlerExceptionResolverTests { assertEquals("Invalid view name returned", "Y:BindException", mav.getViewName()); } + @Test + public void inherited() { + IOException ex = new IOException(); + InheritedController controller = new InheritedController(); + ModelAndView mav = exceptionResolver.resolveException(request, response, controller, ex); + assertNotNull("No ModelAndView returned", mav); + assertEquals("Invalid view name returned", "GenericError", mav.getViewName()); + } + @Test(expected = IllegalStateException.class) public void ambiguous() { IllegalArgumentException ex = new IllegalArgumentException(); @@ -119,6 +128,16 @@ public class AnnotationMethodHandlerExceptionResolverTests { } + @Controller + private static class InheritedController extends SimpleController { + + @Override + public String handleIOException(IOException ex, PortletRequest request) { + return "GenericError"; + } + } + + @Controller private static class AmbiguousController {