Spring 3 Interceptor Order

戏子无情 提交于 2019-12-04 04:16:48

I looked at the underlying implementation, the global interceptors(not associated to any path mapping) get executed before the mapped interceptors (with associated path patterns). So if you want the homeInterceptor to be executed before the allInterceptor, the allInterceptor may have to be made a mapped interceptor(by providing a path pattern).

These are the two methods that record the interceptors and find the interceptors at runtime: org.springframework.web.servlet.handler.AbstractHandlerMapping.initInterceptors()

org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandlerExecutionChain(Object, HttpServletRequest)

It seems in Spring 3 they have removed the logic that executes the global interceptors first. Now the interceptors are executed in the order in which they are declared.

Note however that the postHandle of the interceptors is executed in REVERSE order!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!