本文中只测试了, 异常处理接口HandlerExceptionResolver
步骤
1.自定义异常类:
/** * 自定义全局异常处理类 */ public class CustomerExceptionResolver implements HandlerExceptionResolver { @Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { return new ModelAndView("500", "message", ex.getMessage()); } }
2.springMvc配置文件中增加
<!-- 注册全局异常处理类 --> <bean class="zpark.exception.CustomerExceptionResolver"/>
3.controller
@RequestMapping("/test") public String test(){ throw new RuntimeException("出错了,请修复.."); }
4.异常页面捕获异常信息
系统异常:${message }