ResponseEntityExceptionHandler()
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 HttpMessageConverter, in contrast to org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver which returns a org.springframework.web.servlet.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 sub-class to be detected, ExceptionHandlerExceptionResolver must be configured.
Author
Rossen Stoyanchev
Since
3.2
See Also
#handleException(Exception, WebRequest)org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver