티스토리 뷰
Spring MVC - HandlerInterceptor 구현 및 등록
-
간단한 인터셉터 구현
-
HelloInterceptor.java
- SimpleInterceptor
- Interceptor 실행결과
- preHandle: 호출의 정순
- postHandle: 호출의 역순
- afterCompletion: 호출의 역순
정리
- Interceptor생성시 HandlerInterceptor Interface를 구현하여 Interceptor를 작성할 수 있다.
- 생성한 Interceptor를 등록하고싶다면 WebMvcConfigurer Interface의 addInterceptors메서드를 통해 등록이 가능하다.
- Interceptor등록시 우선순위를 지정해 줄 수 있으며, 우선순위를 지정하지 않았다면 등록한 순서대로 우선순위가 지정된다.
- 이때 우선순위는 음수가 우선순위가 더 높다.
- Interceptor등록시 특정 Url Pattern의 요청시에만 동작하도록 등록이 가능하다.
'Spring' 카테고리의 다른 글
Spring - MVC - HttpMessageConverter_JSON (0) | 2019.07.21 |
---|---|
Spring - MVC ResourceHandler (0) | 2019.07.16 |
Spring MVC - Handler Interceptor (0) | 2019.07.15 |
Spring - MVC DomainClassConverter (0) | 2019.07.14 |
Spring - MVC WebMvcConfigurer_Formatter (0) | 2019.07.14 |
댓글