开发者

Spring Exception handlers - using both annotated and xml defined

开发者 https://www.devze.com 2023-04-01 22:29 出处:网络
I\'ve annotated one of my controllers with @ExceptionHandler, in hopes of handling the exceptions for that cla开发者_如何转开发ss within the following method.

I've annotated one of my controllers with @ExceptionHandler, in hopes of handling the exceptions for that cla开发者_如何转开发ss 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?


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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消