ste*_*bot 5 java spring spring-mvc
我使用XML映射处理在Spring 2.5下开发的应用程序.最近,我们将JARS升级到Spring 3.0,并添加了一些组件扫描,试图使用Spring 3.0的新MVC功能,同时仍然维护我们现有的XML映射.
但是,如果我们要添加以下内容以启用sping mvc注释
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- The following is the new XML configuration that we have tried to add -->
<mvc:annotation-driven/>
<!-- ... old XML mappings -->
</beans>
Run Code Online (Sandbox Code Playgroud)
然后,Spring只查找用@Controller注释的控制器,我们的旧XML映射似乎被忽略了.是这个问题的唯一解决方案,我们需要将所有旧的XML映射更新为基于注释(一项艰巨的任务)还是有其他解决方案?
我们旧的XML映射的一个示例如下:
<bean id="loginController" class="com.app.controller.login.LoginController">
<property name="loginService" ref="loginService"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
LoginController扩展了SimpleFormController.许多其他旧的控制器要么扩展SimpleFormController,要么扩展MultiActionController.
这就是我们的控制器的映射方式.
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/login">loginController</prop>
...
Run Code Online (Sandbox Code Playgroud)
我很确定控制器映射是其中之一,但是如果您有以下 bean 设置,基于注释的功能(例如 @RequestParam)应该仍然可以工作...
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
Run Code Online (Sandbox Code Playgroud)
我不记得我是否成功地混合并匹配了您所描述的内容,因此请发表评论并提供任何反馈。
我怀疑您是否可以在 XML 和注释中定义 URL 映射处理程序,因为servlet 上下文只能使用一个映射器,这意味着您的注释和 XML 映射必须完全对齐。
| 归档时间: |
|
| 查看次数: |
4795 次 |
| 最近记录: |