The first step: Dispatcher Front controller of the source code in the default
Private Boolean Throwexceptionifnohandlerfound = False, indicating that if no matching executor is found, no exception is thrown handler not found, so the 404 exception is to be captured if this property is to be changed to True
You can use the configuration of Web. XML Dispatcher This parameter is true for specific configuration parameters, please Baidu, here does not elaborate
Step Two: Create a new class, add @controlleradvice annotations on this class, meaning that the controller enhancement means that the note can be scanned by spring, and then define a method in this class to handle the exception you intercepted, note that
Add the @exceptionhandler annotation to the top of the method, and the value of the annotation is the class bytecode object of the exception you want to intercept.
Step three: Basically all the work is done on the second step, you just have to make sure that your annotations are scanned in the scan package of the spring MVC configuration file, and then write down the specific processing you have for the interception.
Precautions:
Do not configure the MVC configuration file <mvc:default-servlet-hanler/> If there is a configuration that will affect your definition of global MVC an interception effect Oh, basically the test is successful, if you did not succeed in stating that there is no right,
Basically in accordance with the above steps can be, specific configuration problems to solve their own, the main idea is right, the implementation process has encountered problems is inevitable, I can not be all the possible problems listed out to everyone reference, basically
According to the main steps did not do, the details of the small problem will depend on everyone to study, but also exercise their ability to solve problems, and the knowledge to deepen the impression of understanding, refueling OH
SPRINGMVC Global Exception interception processing @ControllerAdvice annotations @ExceptionHandler