Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring:SimpleMappingExceptionResolver与@ExceptionHandler一起使用?_Spring_Spring Mvc - Fatal编程技术网

Spring:SimpleMappingExceptionResolver与@ExceptionHandler一起使用?

Spring:SimpleMappingExceptionResolver与@ExceptionHandler一起使用?,spring,spring-mvc,Spring,Spring Mvc,我喜欢,因为在一个地方,我有web应用程序中所有控制器的所有异常->视图映射(我想是这样)。要自定义特定控制器中的某些异常,我想使用@ExceptionHandler,但它不能一起工作-所有异常都由SimpleMappingExceptionResolver处理。如何使这两者协同工作 @Controller public class SomeController { ... @ExceptionHandler(SomeException.class) public Mo

我喜欢,因为在一个地方,我有web应用程序中所有控制器的所有异常->视图映射(我想是这样)。要自定义特定控制器中的某些异常,我想使用
@ExceptionHandler
,但它不能一起工作-所有异常都由
SimpleMappingExceptionResolver
处理。如何使这两者协同工作

@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> 

...

简短回答:
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"/>


完整故事:.

使用Spring MVC的新基础架构(
RequestMappingHandlerMapping
RequestMappingHandlerAdapter
)在第二个bean标记上缺少结尾您必须使用
ExceptionHandlerExceptionResolver
而不是
AnnotationMethodHandlerExceptionResolver
。我们现在也可以使用HandlerExceptionResolver组件-