marioosh
marioosh

Reputation: 28566

Spring: SimpleMappingExceptionResolver together with @ExceptionHandler?

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> 

Upvotes: 7

Views: 5352

Answers (1)

abalogh
abalogh

Reputation: 8281

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.

Upvotes: 12

Related Questions