Spring:SimpleMappingExceptionResolver 与 @ExceptionHandler 一起使用?
我喜欢 < code>SimpleMappingExceptionResolver,因为在一个地方我拥有网络应用程序中所有控制器的所有异常->视图映射(我想是这样)。要在特定控制器中自定义某些异常,我想使用@ExceptionHandler
,但它不能一起工作 - 所有异常均由SimpleMappingExceptionResolver
处理。如何使这一起工作?
@Controller
public class SomeController {
...
@ExceptionHandler(SomeException.class)
public ModelAndView handleException(Exception ex) {
// ...
}
}
简单映射异常解析器:
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="error"/>
<property name="exceptionMappings">
...
</property>
</bean>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:
p:order
全文:springsource 论坛。
Short answer:
p:order
Full story: springsource forum.