반응형
spring 예외처리
-
spring @ControllerAdvice, @ExceptionHandler 예외처리 방법Spring/Annotation 2023. 6. 8. 18:02
@ExceptionHandler @ExceptionHandler 는 @Controller , @RestController 가 적용된 Bean 에서 발생하는 예외를 잡아서 하나의 메서드에서 처리해주는 기능이다. @ExceptionHandler 에 설정한 예외가 발생하면 handler가 실행된다. @RestController public class MyRestController { ... ... @ExceptionHandler(NullPointerException.class) public Object nullex(Exception e) { System.err.println(e.getClass()); return "myService"; } } 위와 같이 적용하기만 하면 된다. @ExceptionHandler라..