@RestControllerAdvice

Java에서는 예외 처리를 위해 try-catch를 사용해야 하지만 try-catch를 모든 코드에 붙이는 것은 비효율적이다. Spring은 전역적으로 예외를 처리할 수 있는 @ControllerAdvice와 @RestControllerAdvice 어노테이션을 지원한다. @RestControllerAdvice는 @ControllerAdvice와 달리 @ResponseBody가 붙어 있어 응답을 Json으로 내려준다는 점이 다르다. @ControllerAdvice @ExceptionHandler, @ModelAttribute, @InitBinder 가 적용된 메서드에 AOP를 적용해 Controller 단에 적용하기 위해 고안된 어노테이션 @Controller에 대한 전역적으로 발생할 수 있는 예외를 처리..
계란소년
'@RestControllerAdvice' 태그의 글 목록