Spring에서 Exception 처리는 총 3가지
- 전역 처리 Global Level using - @ControllerAdvice
- 컨트롤러단에서 처리 Controller Level using - @ExceptionHandler
- 메소드단위 처리 Method Level using - try/catch
1. @ControllerAdvice
- 공통 Exception 클래스를 만들고 해당 어노테이션 추가
- 서비스, 컨트롤러단에서는 exception을 throw 하는 역할만하고 공통 클래스에서 일괄처리
2. @ExceptionHandler
- 컨트롤러 별로 Exception 처리
3. try/catch
- 메소드 단위에서 exception 처리
- 안티패턴, 불가피한경우 구체적인 Exception 지정
*** cheese10yun 블로그에 설명이 너무 잘돼있음
출처: https://springboot.tistory.com/33 [스프링부트는 사랑입니다]
스프링부트 : REST 어플리케이션에서 예외처리하기
스프링부트 : REST어플리케이션에서 예외처리하기 (원문소스: http://www.ekiras.com/2016/02/how-to-do-exception-handling-in-springboot-rest-application.html) 기억할 점 스프링 부트 어플리케이션에서 예외..
springboot.tistory.com
https://cheese10yun.github.io/spring-guide-exception/
Spring Guide - Exception 전략 - Yun Blog | 기술 블로그
Spring Guide - Exception 전략 - Yun Blog | 기술 블로그
cheese10yun.github.io
https://groups.google.com/forum/#!topic/ksug/5xeN3gDSbu8
Google 그룹스
groups.google.com
'Web > Spring Framework' 카테고리의 다른 글
Spring Transaction 처리 (0) | 2020.01.14 |
---|---|
CSRF (Cross-site Request Forgery, 사이트 간 요청 위조) (0) | 2020.01.09 |
SpringMVC - View의 이해 (1) | 2018.08.31 |
Spring Boot 세팅하기1 - 프로젝트 생성 (0) | 2018.08.28 |
Spring Framework 세팅하기1 - 설치 (0) | 2018.05.29 |