ExceptionController.java (해당 파일이 위치한 패키지 빈 등록 되어있는지 체크하기)
@ControllerAdvice
public class ExceptionController {
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST) //200->400 상태코드 변경해서 응답
public String runtimeCatcher(Exception e, Model model) {
model.addAttribute("msg", "400");/*model.addAttribute("e", e);*/
return "exception/error";
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) //500
public String commonCatcher(Model model){
model.addAttribute("msg", "500");
return "exception/error";
}
404는 잡히지가 않아 web.xml에 추가하니깐 잡힌다.
404는 DispatcherServlet에서 넘어갈 때 발견되서 그런 것 같다.
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/views/exception/error.jsp</location>
</error-page>