我有
@Controller
@RequestMapping(value="core/*")
public class CoreController {
public static String exceptionOccurredView = "/core/exceptionOccurred";
@ExceptionHandler(Throwable.class)
public ModelAndView exceptionOccurred(Throwable exception, HttpServletResponse response, HttpServletRequest request) {
ModelAndView mv = new ModelAndView();
mv.setViewName ( exceptionOccurredView );
mv.addObject ( "requestedUrl", Core.getCurrentUrlWithParams() );
mv.addObject ( "exception", exception );
System.out.println( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + Core.getCurrentUrlWithParams() );
return mv;
}
@RequestMapping
public void test0(HttpServletResponse response, HttpServletRequest request) throws IOException {
throw new IOException();
}
}
这适用于核心 url 下发生的所有异常。
如果我去网址
本地主机:8080/core/test0
显示错误页面。另外,如果我去:
本地主机:8080/核心/actionDoesNotExist
但如果我使用:
本地主机:8080/controllerDoesNotExist/test0
没有显示错误,因为注释 @ExceptionHandler 仅对每个控制器有效。
那么如何实现一个全局的、非控制器附加的异常/错误处理程序呢?