반응형
이번에는 Interceptor 에 대해서 포스팅하고자 합니다.
Interceptor 에 대한 기본이해는 이미 하셨으리라 생각하고 설정하는 부분만 나갑니다.
src/main/java/kr.mythsoft.stats/common/Interceptor/StatsInterceptor.java
package kr.mythsoft.stats.common.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by kmbaek on 2016-10-13.
*/
@Component
public class StatsInterceptor extends HandlerInterceptorAdapter {
private static final Logger logger = LoggerFactory.getLogger(StatsInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
logger.info("Interceptor > preHandle");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
logger.info("Interceptor > postHandle");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object object, Exception arg3) throws Exception {
logger.info("Interceptor > afterCompletion" );
}
}
src/main/java/kr.mythsoft.stats/config/StatsConfig.java
package kr.mythsoft.stats.config;
import kr.mythsoft.stats.common.Interceptor.StatsInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* Created by kmbaek on 2016-10-13.
*/
@Configuration
public class StatsConfig extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new StatsInterceptor());
}
}
결과화면
반응형
'Programming > Spring Framework' 카테고리의 다른 글
[Spring Boot] Filter 적용 (0) | 2016.10.19 |
---|---|
[Spring Boot] jasypt 암호화 적용 (0) | 2016.10.18 |
[Spring Boot] tiles3 설정하기 (3) | 2016.10.13 |
[Spring Boot] SQL Logging 사용 (0) | 2016.10.13 |
[Spring Boot] 초기 설정 (1) | 2016.10.13 |