@ControllerAdvice를 통한 예외처리 분리, 통합하기
·
Languages | Frameworks/Spring
@ControllerAdvice @ExceptionHandler가 하나의 클래스에 대한 것이라면, @ControllerAdvice는 모든 @Controller 즉, 전역에서 발생할 수 있는 예외를 잡아 처리해주는 annotation이다. 예를들어 모든 jsp(ex. header)에 같은 modelAttribute를 던져줘야 한다면, 아래와 같이 사용하면 된다. @ControllerAdvice public class AdviceController { @ModelAttribute("modelAttribute key값") public String getWhereIP() { return "modelAttribute value값"; }