→ ExceptionHandler에 등록하기 위한 어노테이션
→ @ExcpetionHadler와 같이 쓰인다. 이 어노테이션이 모든 예외들이라는 관심사항을 뽑아 관리하는 AOP의 대표적인 예시이다.
@RestControllerAdvice
public class GlobalExceptionHandler {
//Convertor 에서 바인딩 실패시 발생하는 예외
// value : 해당 예외 class에 대해 다루겠다는 뜻
@ExceptionHandler(value = {HttpMessageNotReadableException.class})
public ResponseDto<?> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) {
log.error(
"handleHttpMessageNotReadableException() in GlobalExceptionHandler throw HttpMessageNotReadableException : {}", e.getMessage()
);
return ResponseDto.fail(new CommonException(ErrorCode.BAD_REQUEST_JSON));
}
....
}
@RequiredArgsController → 초기화 되지 않은 final이나 @NotNull 로 정의된 필드에 의존성을 알아서 넣어준다.