私は持っている
@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 で発生するすべての例外に対して正常に機能します。
URLに行くと
ローカルホスト:8080/core/test0
エラーページが表示されます。また、私が行った場合:
ローカルホスト:8080/core/actionDoesNotExist
しかし、私が使用する場合:
ローカルホスト:8080/controllerDoesNotExist/test0
注釈 @ExceptionHandler はコントローラーごとにのみ有効であるため、エラーは表示されません。
では、コントローラーに接続されていないグローバルな例外/エラーハンドラーをどのように実現できますか?