0
저는 Spring Web Flow의 초보자입니다. 나는 예외를 기록하는 가장 쉬운 방법이 플로우 파일 내에 무엇인지 알아 내려고하고있다. exception-handler
이라는 태그가 있지만 예외 기록 방법에 대한 문서를 찾을 수 없습니다. 타사 라이브러리의 예외가 기록 된 것을 알고 있지만 (spring
, hibernate
) 예외를 처리하고 자체 로그 항목을 만들고 싶습니다. @ControllerAdvice
클래스
를 사용
처리 @ExceptionHandler
@Controller
public class ExceptionHandlingController {
@ExceptionHandler(Exception.class)
public ModelAndView getExceptionPage(Exception e, HttpServletRequest request) {
// Catches all exception
// Do anything with Exception object here
if (isAjax(request)) {
// If exception comes for Ajax requests
ModelAndView model = new ModelAndView("forward:/app/webExceptionHandler/ajaxErrorRedirectPage");
model.addObject("exception", exception);
model.addObject("url", req.getRequestURL());
model.setViewName("error");
return model;
} else {
// If exception comes for all non Ajax requests
ModelAndView model = new ModelAndView("forward:/app/webExceptionHandler/nonAjaxErrorRedirectPage");
model.addObject("exception", exception);
model.addObject("url", req.getRequestURL());
model.setViewName("error");
return model;
}
}
@ExceptionHandler({SQLException.class,DataAccessException.class})
public String databaseError() {
// Catches specific exception SQLException
return "databaseError";
}
private static boolean isAjax(HttpServletRequest request) {
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
}
}
글로벌 예외를 사용
는
하지만이 컨트롤러를 플로 파일에서 어떻게 구성 할 수 있습니까? 예외 처리기로 선언해야합니까? – user3254515
@ user3254515 자세한 내용은 [참조] (http://ankursinghal86.blogspot.in/2014/07/exception-handling-in-spring-mvc.html)를 참조하십시오. –