Spring中没有HandlerInterceptor如何拦截所有控制器的所有请求?
我有一个需求,在spring 2.5中拦截所有请求。我不想使用 HandlerInterceptor 来拦截请求,因为它需要使用上下文文件中的每个 SimpleUrlHandlerMapping bean 进行配置。是否有另一种方法可以在不使用 HandlerInterceptor 的情况下拦截所有请求?
I have a requirement to intercept all the request in spring 2.5. I don't want to use HandlerInterceptor
to intercept the request because it requires to configure it with every SimpleUrlHandlerMapping
bean in the context files. Is there another way to intercept all the request without using HandlerInterceptor
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以实现一个过滤器并将其映射到 web.xml 中的 DispatcherServlet。那么您应该能够拦截对 Spring MVC 发出的所有请求。
简而言之:
将过滤器添加到 web.xml
<前><代码><过滤器>
<过滤器名称>MyFilter
<过滤器类>mypackage.MyFilter
然后将其映射到 DispatcherServlet(servlet-name 应该与为 Spring Dispatcher servlet 定义的相同。
如果需要访问过滤器中的 Spring ApplicationContext ,使用静态方法
You could implement a filter and map it to the DispatcherServlet in web.xml. Then you should be able to intercept all request made to Spring MVC.
In short:
Add the filter to web.xml
and then map it to the DispatcherServlet (servlet-name should be the same that is defined for the Spring Dispatcher servlet.
If you need access to the Spring ApplicationContext in the filter, use the static method