티스토리 뷰

Framework/SPRING BOOT

HandlerInterceptor

xoo | 수진 2023. 9. 25. 17:37

브라우저필터(Filter)DispatcherServlet인터셉터(preHandle)Controller
                                                        | 위임          ← 인터셉터(postHandle)
인터셉터(afterCompletion)        jsp

 


 

스프링 프레임워크

  • 의존성 추가 없음
  • @Component(”xxx”)
    public class MyHandlerInterceptor extends HandlerInterceptorAdapter {}
    필요한 메서드 재정의해서 사용
  • servlet-context.xml
<mvc:interceptors>		 
	<mvc:interceptor>		   
		<mvc:mapping path="/loginCheck/*"/>		    
			<ref bean="xxx"/>		 
	</mvc:interceptor>

 

 

 

 

 

스프링 부트

  • 의존성 추가 없음
  • @Component(”xxx”)
    public class MyHandlerInterceptor implements HandlerInterceptor {}
    ⇒ 필요한 메서드 재정의해서 사용
        왜? default 메서드로 되어있음
       ( HandlerInterceptorAdaptor는 deprecated 됨 )
  • servlet-context.xml 대신에 빈(설정목적)을 이용해서 Interceptor 등록한다.
    @Configuration
    public class WebConfig implements WebMvcConfigurer{
            //이전 servlet-context.xml 에서 했던 여러 기능을 가진 메서드 재정의해서 사용
    }

https://docs.spring.io/spring-boot/docs/2.7.16/reference/html/web.html#web

 

Web

Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest

docs.spring.io

 

@Configuration
public class WebConfig implements WebMvcConfigurer{
    //이전 servlet-context.xml 에서 했던 여러 기능을 가진 메서드 재정의해서 사용

	  @Autowired
		MyHandlerInterceptor interceptor;
		
		@Override
		public void addInterceptors(InterceptorRegistry registry) {
			registry.addInterceptor(interceptor)
			        .addPathPatterns("/login", "/mypage");
		}
}

 


 

'Framework > SPRING BOOT' 카테고리의 다른 글

@Value  (0) 2023.09.25
springboot에서 설정 정보 파일  (0) 2023.09.25
file upload  (0) 2023.09.25
@RestController  (0) 2023.09.25
JSON 처리(@RequestBody)  (0) 2023.09.25
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함