Spring Exception handlers – using both annotated and xml defined

I’ve annotated one of my controllers with @ExceptionHandler, in hopes of handling the exceptions for that class within the following method.

We also have a site-wide exception handler defined in XML (SimpleMappingExceptionResolver).

The SimpleMappingExceptionResolver is still handling exceptions in my controller with an @ExceptionHandler annotation.

How can I get the controller specific exception handler to deal with exceptions coming from its controller?

Answer

Answered in tremendous depth and clarity here:

Basically it says to add the AnnotationMethodHandlerExceptionResolver manually (adding SimpleMappingExceptionResolver causes the Annotation resolver not to be automatically added), and set the order of the two Resolvers.

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver" 
      p:order="1" />

Leave a Reply

Your email address will not be published. Required fields are marked *