开发者

Spring 3.0 URL Mapping Issues

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 a开发者_如何学Cn 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜