[Spring boot] @ControllerAdvice 와 @ExceptionHandler 으로 간단한 Global Exception Handler

유존돌돌이·2022년 2월 22일
0

Spring boot

목록 보기
12/20
post-thumbnail
@ControllerAdvice // 모든 @Controller 즉, 전역에서 발생할 수 있는 예외를 잡아 주는 annotation
@RestController
public class GlobalExceptionHandler {
	
	@ExceptionHandler(IllegalArgumentException.class)
	public String handleArgumentException(IllegalArgumentException e) {
		return "<h1>"+e.getMessage()+"</h1>";		
	}
	
	@ExceptionHandler(EmptyResultDataAccessException.class)
	public String handleEmptyResultDataAccessException(EmptyResultDataAccessException e) {
		return "<h1>"+e.getMessage()+"</h1>";
	}
	
}

0개의 댓글