spring3 之 升格Spring从2.5.6至3.1.2过程

[size=medium]
http://www.myexception.cn/software-architecture-design/963643.html

升级Spring从2.5.6至3.1.2过程实录
1、引言
项目使用的是Spring MVC + Spring + iBatis框架,Spring和Spring MVC的版本都是2.5.6,但项目功能开发上需要支持REST功能,Spring MVC 2.5.6对REST的支持不够,于是决定升级Spring及Spring MVC至最新版本3.1.2

2、准备
至SpringSource的官方网站下载最新的Spring版本(当前最新release版本为3.1.2),地址
http://www.springsource.org/download/community

3、更新过程
(1)更新Spring和Spring MVC相关的jar
删除原有的Spring依赖,项目原有的依赖为
spring-2.5.6.jar
spring-webmvc-2.5.6.jar
spring-test-2.5.6.jar

增加项目新版的Spring依赖文件
// aop的依赖
aopalliance-1.0.jar
// 增加spring3.1.2相关jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar


(2)更新web.xml中的Spring启动配置
原内容:
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

修改为:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


(3)更新Spring的所有XML配置文件的头部
原有applicationContext*.xml的头部
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

修改为:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

即:将applicationContext*.xml头部中的所有的2.5修改为3.0

(4)更新Spring MVC的所有XML配置文件的头部
原有servlet*.xml的头部
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

修改为:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

即:将servlet*.xml头部中的所有的2.5修改为3.0

(5)修改所有的继承SimpleJdbcDaoSupport的文件
原代码:
public class AAASDao extends SimpleJdbcDaoSupport {
...(略)
}

修改为:
public class AAASDao extends JdbcDaoSupport {
...(略)
}

注:SimpleJdbcDaoSupport 及SimpleJdbcTemplate,已经在3.1.2版本中被废弃原因是JdbcDaoSupport 或NamedParameterJdbcDaoSupport已经提供了其所有功能,可替换为JdbcDaoSupport 或NamedParameterJdbcDaoSupport(派生于JdbcDaoSupport)
参考地址http://kimsoftware.iteye.com/blog/1554218

(6)另外,Spring MVC基于注解的Junit测试的注解
原内容
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class BaseTest extends AbstractJUnit4SpringContextTests {
...(略)
}

@RunWith(SpringJUnit4ClassRunner.class)会报错,网上找了一下,不知如何处理,后来由于该部分的代码,项目中已经没有用到了,故将其删掉了,有兴趣的童靴可以再找找修正方法

4、运行&测试
经过上面的处理过程,项目已不再提示错误,运行web项目后,经测试项目的功能基本没有问题,升级完成。

5、总结
项目升级后基本的测试是没有问题的,但不知道有没有其它未知的问题,有待后续的进一步观察和测试[/size]
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值