Spring MVC 注解和 HandleInterceptors
我正在使用 Spring 3.x MVC 进行一个项目,并使用注释实现了我们的控制器。我们最近需要实现 HandlerInterceptors,但我遇到了一些问题。当我在配置 (dispatcher-sevlet.xml
) 中指定时,拦截器
<bean id="myInterceptor" class="com.myProject.controllers.MyInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list><ref bean="myInterceptor"/></list>
</property>
</bean>
一切正常,也就是说,任何 URL 匹配都会命中 myInterceptor 代码。当我尝试添加
<property name="mappings">
<props>
<prop key="/addFile.request">myFileController
</prop>
</props>
</property>
时,我从未点击 myInterceptor
代码...我还尝试使用 @RequestMapping
注释来实现上述映射代码。
I am on a project using Spring 3.x MVC, and have implemented our controllers using annotations. We recently have a requirement to implement HandlerInterceptors, to which I have had some problems. When I specify in my configuration (dispatcher-sevlet.xml
), the interceptor
<bean id="myInterceptor" class="com.myProject.controllers.MyInterceptor" />
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list><ref bean="myInterceptor"/></list>
</property>
</bean>
then all is well, that is, any URL matches hits the myInterceptor code. When I try to add
<property name="mappings">
<props>
<prop key="/addFile.request">myFileController
</prop>
</props>
</property>
then I never hit the myInterceptor
code...I have also tried to implement the above mapping code using @RequestMapping
annotations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用基于注释的配置,则使用
标记来配置拦截器会更容易。例如
It's easier to use the
<mvc:interceptors>
tag to configure interceptors if you're using annotation-based configuration.E.g