springboot global exception interception Source Reading

In springboot we can declare an exception interception by notes @ControllerAdvice class, for specific exception class interceptor class thrown out by @ExceptionHandler, we can read the source code and debug an exception to interpret the interception mechanism springboot.

Before looking at abnormal interception mechanism, and I quote others' images under a general introduction springmvc generally call flow

 

Abnormal intercept process flow:

1. The first calls doDispatch distribution request of DispatcherServlet

2. The process distribution method results processDispatchResult

 

 3. If the result of the process of distribution exception occurs, set dispatchException variable corresponding exception if an exception is called processHandlerException method for exception handling, if the acquisition is ModelAndViewDefiningException its ModelAndView, if not the method is called processHandlerException exception handling, the final call AnnotationMethodHandlerExceptionResolver of doResolveException parse exception and return ModelAndView.

 

 

 

 

 

 Note: springmvc process Reprinted from https://www.cnblogs.com/whuthxb/p/9385761.html

Guess you like

Origin www.cnblogs.com/cncxy-20170829/p/11613050.html