在 spring 3.1 中,我错过了使用通用基本控制器进行默认 URL 映射的功能。请看以下示例:
<bean id="appleController" class="de.mw.mwdata.core.web.control.GenericEntityController" />
<bean id="peachController" class="de.mw.mwdata.core.web.control.GenericEntityController" />
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/admin/apple/list.htm">appleController</prop>
<prop key="/admin/peach/list.htm">peachController</prop>
<prop key="/admin/strawberry/list.htm">strawberryController</prop>
</props>
</property>
</bean>
<mvc:annotation-driven />
<context:component-scan base-package="de.mw.mwdata.app.admin.web.control" >
</context:component-scan>
这里是 GenericEntityController 和草莓控制器的相关代码片段:
@RequestMapping("/admin/**")
public class GenericEntityController<E extends AbstractEntity> {
...
@RequestMapping(value = "**/list.htm", method = RequestMethod.GET)
public ModelAndView list( final HttpServletRequest request, final HttpServletResponse response ) {
...
}
}
package de.mw.mwdata.app.admin.web.control;
@Controller
@RequestMapping("/admin/strawberry/")
public class StrawberryController extends GenericEntityController<Strawberry> {
...
}
}
所以在春季 3.1 和 SimpleUrlHandlerMapping 之前,我有两个控制器实例(GenericEntityController)用于上下文路径 apple 和 peach 和一个带注释的控制器实例 StrawberryController。到 /list.htm 方法的映射是由 @RequestMapping 完成的,特别是在方法级别上。我的问题:在 spring-mvc 3.1 中,SimpleUrlHandlerMapping 不再适用于带注释的@RequestMapping。我得到以下异常:
Cannot map 'peachController' bean method
public org.springframework.web.servlet.ModelAndView de.mw.mwdata.core.web.control.GenericEntityController.list(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
to {[/admin/**/list.htm],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'appleController' bean method
public org.springframework.web.servlet.ModelAndView de.mw.mwdata.core.web.control.GenericEntityController.list(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) mapped.
如何在 spring 3.1 中替换此配置?