Filter/Interceptor/Aspect拦截Rest服务

Filter implements Filter 可以拿到原始http请求的信息,但是拿不到处理方法的信息

init(FilterConfig filterConfig)

doFilter(ServletRequest request, ServletResponse response, FilterChain chain)

destroy()

Interceptor implements HandlerInterceptor  可以拿到原始http请求的信息,也可以拿到处理方法的信息,但是拿不到方法的参数值

preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)

postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView arg3)

afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception)

@Aspect   可以拿到方法和方法的参数值,但是拿不到原始http请求的信息

调用流程:

如果不抛出异常的情况下:

Filter -> Interceptor -> @Aspect -> Controller

            方法:init -> preHandle -> @Aspect  -> postHandle -> afterCompletion -> destroy

如果抛出异常:

Controller -> @Aspect  -> @ControllerAdvice -> Interceptor -> Filter

你可能感兴趣的:(Filter/Interceptor/Aspect拦截Rest服务)