public class BootInterceptor implements HandlerInterceptor {
public static Log LOG = LogFactory.getLog(BootInterceptor.class);
private long time = System.currentTimeMillis();
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2) throws Exception {
time = System.currentTimeMillis();
LOG.info(req.getRequestURI() + ":" +"preHandle");
return true;
}
public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object arg2, Exception arg3)
throws Exception {
long interval = System.currentTimeMillis() - time;
LOG.info(req.getRequestURI()+":"+"afterCompletion,time used:"+interval);
}
public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object arg2, ModelAndView arg3)
throws Exception {
LOG.info(req.getRequestURI()+":"+"postHandle");
}
}
@Configuration
public class BootWebAppConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new BootInterceptor()).addPathPatterns("/**");
super.addInterceptors(registry);
}
}