Override spring @ExceptionHandler methods

If I have a Spring controller with two SEPARATE methods, one of which is annotated:



and the other is annotated:



And my controller is throwing SubException.class

, is it handled by both methods or just @ExceptionHandler(SubException.class)



source to share

3 answers

One handler will be called based on the best match.

The exact implementation is in AnnotationMethodHandlerExceptionResolver.findBestExceptionHandlerMethod(Object,Exception)



You can create your own annotation class which will be an exception. And after that you need to provide the class annotation instead of the Exception handler.

Please let me know if you have any questions.



Handlers usually implement Spring s ordered interface so you can determine the order in which the handlers are executed.

see Exception Handling in Spring MVC



All Articles