티스토리 뷰


@ControllerAdvice 를 통해서 error 처리가 가능하다.


두개 이상의 @ControllerAdvice 가 있을 경우, 처리 순서를 지정해야 하는 경우가 있다.


이럴 경우. @Order 어노테이션을 이용해서 우선순위를 지정한다.


http://stackoverflow.com/questions/19498378/setting-precedence-of-multiple-controlleradvice-exceptionhandlers

class UserProfileException extends RuntimeException {
}

@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
class UserProfileExceptionHandler {
    @ExceptionHandler(UserProfileException)
    @ResponseBody
    ResponseEntity<ErrorResponse> handleUserProfileException() {
        ....
    }
}

@ControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE)
class DefaultExceptionHandler {

    @ExceptionHandler(RuntimeException)
    @ResponseBody
    ResponseEntity<ErrorResponse> handleRuntimeException() {
        ....
    }
}


공지사항