> {
private final Class extends Throwable> handlerExceptionType;
diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java
index 9c8fcc3ee9f98e2f955bd87b3f50f239e2cd46b1..0924c03c87831cb072295727277afbeaccf4e9b6 100644
--- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java
+++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolverTests.java
@@ -30,7 +30,9 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;
+import org.springframework.http.HttpStatus;
/** @author Arjen Poutsma */
public class AnnotationMethodHandlerExceptionResolverTests {
@@ -56,6 +58,8 @@ public class AnnotationMethodHandlerExceptionResolverTests {
ModelAndView mav = exceptionResolver.resolveException(request, response, controller, ex);
assertNotNull("No ModelAndView returned", mav);
assertEquals("Invalid view name returned", "BindException", mav.getViewName());
+ assertEquals("Invalid status code returned", 406, response.getStatus());
+
}
@Test(expected = IllegalStateException.class)
@@ -74,6 +78,7 @@ public class AnnotationMethodHandlerExceptionResolverTests {
}
@ExceptionHandler(BindException.class)
+ @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
public String handleBindException(Exception ex, HttpServletResponse response) {
return ClassUtils.getShortName(ex.getClass());
}
diff --git a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java
index 69586992c2a11dab1219748387ee2f0ec5e6aa95..8489902b479b83938613bfec43085f84405bd729 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/bind/annotation/ExceptionHandler.java
@@ -83,6 +83,10 @@ import java.lang.annotation.Target;
* only applicable in a Servlet environment).
*
*
+ * In Servlet environments, you can combine the {@code ExceptionHandler} annotation
+ * with {@link ResponseStatus @ResponseStatus}, to define the response status
+ * for the HTTP response.
+ *
*
NOTE: @RequestMapping
will only be processed if a
* corresponding HandlerMapping
(for type level annotations)
* and/or HandlerAdapter
(for method level annotations) is