Spring: SimpleMappingExceptionResolver along with @ExceptionHandler?

I like SimpleMappingExceptionResolver because in one place I have all the exceptions -> display mappings for all the controllers in the web application (I suppose that). To set up some kind of exception in a specific controller, I would like to use @ExceptionHandler , but it does not work together - all exceptions are handled by SimpleMappingExceptionResolver . How to make this work collaborative?

 @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> 
+6
source share
1 answer

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 .

+12
source

Source: https://habr.com/ru/post/890495/


All Articles