7

I like SimpleMappingExceptionResolver, because in one place i have all exception->view mappings for all controllers in web-app (i suppose that). To customize some exception in specific controller i would like to use @ExceptionHandler, but it doesn't work together - all exceptions are handled by SimpleMappingExceptionResolver. How to make this work together ?

@Controller
public class SomeController {
    ...

    @ExceptionHandler(SomeException.class)
    public ModelAndView handleException(Exception ex) {
         // ...
    }   

}

SimpleMappingExceptionResolver:

<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    <property name="defaultErrorView" value="error"/>
    <property name="exceptionMappings">
        ...
    </property>
</bean> 

1 Answer 1

12

Short answer: p:order

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver" p:order="1" />
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:order="2" p:defaultErrorView="uncaughtException"/>

Full story: springsource forum.

Sign up to request clarification or add additional context in comments.

3 Comments

missing closing /> on second bean tag
if using the new infrastructure from Spring MVC (RequestMappingHandlerMapping and RequestMappingHandlerAdapter) you must use ExceptionHandlerExceptionResolver instead of AnnotationMethodHandlerExceptionResolver.
we can use the HandlerExceptionResolverComposite as well now- doanduyhai.wordpress.com/2012/05/06/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.