Class ResponseEntityExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

public abstract class ResponseEntityExceptionHandler extends Object
A convenient base class for @ControllerAdvice classes that wish to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods.

This base class provides an @ExceptionHandler method for handling internal Spring MVC exceptions. This method returns a ResponseEntity for writing to the response with a message converter, in contrast to DefaultHandlerExceptionResolver which returns a ModelAndView.

If there is no need to write error content to the response body, or when using view resolution (e.g., via ContentNegotiatingViewResolver), then DefaultHandlerExceptionResolver is good enough.

Note that in order for an @ControllerAdvice subclass to be detected, ExceptionHandlerExceptionResolver must be configured.

Since:
3.2
Author:
Rossen Stoyanchev
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Log
    Common logger for use in subclasses.
    static final String
    Log category to use when no mapped handler is found for a request.
    protected static final Log
    Specific logger to use when no mapped handler is found for a request.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.http.ResponseEntity<Object>
    handleAsyncRequestTimeoutException(org.springframework.web.context.request.async.AsyncRequestTimeoutException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest webRequest)
    Customize the response for AsyncRequestTimeoutException.
    protected org.springframework.http.ResponseEntity<Object>
    handleBindException(org.springframework.validation.BindException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for BindException.
    protected org.springframework.http.ResponseEntity<Object>
    handleConversionNotSupported(org.springframework.beans.ConversionNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for ConversionNotSupportedException.
    final org.springframework.http.ResponseEntity<Object>
    handleException(Exception ex, org.springframework.web.context.request.WebRequest request)
    Provides handling for standard Spring MVC exceptions.
    protected org.springframework.http.ResponseEntity<Object>
    handleExceptionInternal(Exception ex, Object body, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest webRequest)
    A single place to customize the response body of all exception types.
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpMediaTypeNotAcceptable(org.springframework.web.HttpMediaTypeNotAcceptableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for HttpMediaTypeNotAcceptableException.
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpMediaTypeNotSupported(org.springframework.web.HttpMediaTypeNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for HttpMediaTypeNotSupportedException.
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpMessageNotReadable(org.springframework.http.converter.HttpMessageNotReadableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for HttpMessageNotReadableException.
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpMessageNotWritable(org.springframework.http.converter.HttpMessageNotWritableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for HttpMessageNotWritableException.
    protected org.springframework.http.ResponseEntity<Object>
    handleHttpRequestMethodNotSupported(org.springframework.web.HttpRequestMethodNotSupportedException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for HttpRequestMethodNotSupportedException.
    protected org.springframework.http.ResponseEntity<Object>
    handleMethodArgumentNotValid(org.springframework.web.bind.MethodArgumentNotValidException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for MethodArgumentNotValidException.
    protected org.springframework.http.ResponseEntity<Object>
    handleMissingPathVariable(org.springframework.web.bind.MissingPathVariableException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for MissingPathVariableException.
    protected org.springframework.http.ResponseEntity<Object>
    handleMissingServletRequestParameter(org.springframework.web.bind.MissingServletRequestParameterException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for MissingServletRequestParameterException.
    protected org.springframework.http.ResponseEntity<Object>
    handleMissingServletRequestPart(org.springframework.web.multipart.support.MissingServletRequestPartException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for MissingServletRequestPartException.
    protected org.springframework.http.ResponseEntity<Object>
    handleNoHandlerFoundException(NoHandlerFoundException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for NoHandlerFoundException.
    protected org.springframework.http.ResponseEntity<Object>
    handleServletRequestBindingException(org.springframework.web.bind.ServletRequestBindingException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for ServletRequestBindingException.
    protected org.springframework.http.ResponseEntity<Object>
    handleTypeMismatch(org.springframework.beans.TypeMismatchException ex, org.springframework.http.HttpHeaders headers, org.springframework.http.HttpStatus status, org.springframework.web.context.request.WebRequest request)
    Customize the response for TypeMismatchException.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait