티스토리 뷰
1. create some interceptor class
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.WebContentInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
public class SomeInterceptor extends WebContentInterceptor {
@Autowired
private SomeRequestProxy someRequestProxy;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
log.info("SomeInterceptor preHandle");
someRequestProxy.setPre("SomeInterceptor setPre");
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
log.info("SomeInterceptor postHandle");
someRequestProxy.setPost("SomeInterceptor setPost");
log.info(someRequestProxy.toString());
}
}
2. create some interceptor bean
@Bean
public SomeInterceptor someInterceptor() {
return new SomeInterceptor();
}
3. regiest some interceptors
public class SomeConfiguration extend WebMvcConfigurerAdapter {
...
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(someInterceptor());
}
}
Interceptor는 controller 이전 / 이후 단계에서 특정 데이터나 비지니스를 처리할 경우 사용한다.
'Programming > Spring' 카테고리의 다른 글
AOP (0) | 2019.03.27 |
---|---|
Request Proxy (0) | 2019.03.27 |
Argument Resolver (0) | 2019.03.27 |
DI (Dependency Injection) (2) | 2018.11.01 |
Spring Application Start Flow (0) | 2018.10.06 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- java EqualsAndHashCode
- docker
- Typesafe Config
- Sprint RetryTemplate
- Embeddable Mapping
- Query DSL
- 복합키 Mapping
- @Primary
- Spring Registrar
- Criteria
- java generic
- JPA Criteria
- scikit-learn
- DI
- guava
- Registrar
- Mapping
- Property
- JPA
- spring spel
- Join Table
- Spring JDBC Template
- Discriminate Mapping
- Charles proxy
- Spring
- Embedded Mapping
- java Equals
- Akka
- RetryTemplate
- SmartLifecycle
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함