继承HandlerExceptionResolver接口实现自己的处理方法,如:
public class MyHandlerExceptionResolver implements HandlerExceptionResolver { @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { //添加自己的异常处理逻辑,如日志记录等 // TODO Auto-generated method stub return new ModelAndView("exception"); } }
然后在项目的配置文件中添加:
<bean id="exceptionResolver" class="所在包名.MyHandlerExceptionResolver"/>
时间: 2024-11-03 22:16:07