Spring 3.0 URL 映射问题
我正在 Tomcat 上测试从 Spring 2.0 到 Spring 3.0.5 的升级,并且遇到一个问题:带有尾部斜杠的 URL 与不带尾部斜杠的相同 URL 的映射行为不同。
例如,在我的 Spring 2.0 实现中,根据下面的 Spring MVC XML 配置,以下 URL 将映射到同一个控制器类:
/search/categories
/search/categories//search/categories/
(
<bean id="searchMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="1"/>
<property name="mappings">
<props>
<prop key="/search/categories">categoriesController</prop>
</props>
</property>
</bean>
注意尾部斜杠)未映射到控制器。仅 /search/categories
(无尾部斜杠)被映射。
我知道 XML 配置今后将被弃用,不幸的是,我目前还无法摆脱它。但我不确定为什么 Spring 3.0.5 对于带有尾部斜杠的 URL 有新的行为。对可能的修复有什么建议或想法吗?我是否需要实施 Apache Rewrite 条件来删除 URL 上的尾部斜杠?
感谢您的帮助!
I'm testing an upgrade from Spring 2.0 to Spring 3.0.5 on Tomcat and am having an issue where there is different mapping behavior for URLs that have a trailing slash versus an identical URL without the trailing slash.
For example, in my Spring 2.0 implementation, the following URLs would both map to the same controller class, per the Spring MVC XML configuration below:
/search/categories
/search/categories/
<bean id="searchMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="1"/>
<property name="mappings">
<props>
<prop key="/search/categories">categoriesController</prop>
</props>
</property>
</bean>
However, in Spring 3.0.5, /search/categories/
(note trailing slash) is not mapped to the controller. Only /search/categories
(no trailing slash) gets mapped.
I know that the XML configuration is deprecated going forward and, unfortunately, I'm unable to move off of it just yet. But I am unsure as to why with Spring 3.0.5 there is new behavior for URLs with trailing slashes. Any suggestions or thoughts on a possible fix? Will I need to go as far as implementing an Apache Rewrite condition to remove trailing slashes on URLs?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说最简单的解决方案是 创建一个 BeanPostProcessor 来修剪尾部斜杠。
或者,更好的是
BeanFactoryPostProcessor
,这样您就可以编辑bean定义,而不是实际的bean。I'd say the simplest solution is to create a
BeanPostProcessor
that trims off the trailing slashes.Or, better, a
BeanFactoryPostProcessor
, that way you can edit the bean definitions, not the actual beans.