我正在尝试在Spring 2.5中进行RESTful URL映射。这实质上意味着:/fetch/(something)应全部与控制器提取匹配
控制器将根据参数(某事)做某事
我把它添加到我的弹簧配置中:
<bean id="fetchController" class="(package).fetchController" scope="singleton"/>
<bean id="fetchService" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/fetch/*">fetchController</prop>
</props>
</property>
</bean>
并将以下内容添加到我的web.xml
<servlet-mapping>
<servlet-name>springGlobal</servlet-name>
<url-pattern>/fetch/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>springGlobal</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
但这似乎不正确。日志说:org.springframework.web.servlet.PageNotFound - 在 DispatcherServlet 中找不到名称为 'springGlobal' 的 URI [/fetch/charts] 的 HTTP 请求的映射
控制器处理程序映射是相对于 servlet 映射解析的。因此,您拥有的内容将映射到
/fetch/fetch/*
你应该使用
<property name="mappings">
<props>
<prop key="/*">fetchController</prop>
</props>
</property>