升级Spring从2.5.6至3.1.2过程实录

3 篇文章 0 订阅
[size=x-large][b]1、引言[/b][/size]
项目使用的是Spring MVC + Spring + iBatis框架,Spring和Spring MVC的版本都是2.5.6,但项目功能开发上需要支持REST功能,Spring MVC 2.5.6对REST的支持不够,于是决定升级Spring及Spring MVC至最新版本3.1.2

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

[size=x-large][b]3、更新过程[/b][/size]
[size=large][b](1)更新Spring和Spring MVC相关的jar[/b][/size]
删除原有的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


[size=large][b](2)更新web.xml中的Spring启动配置[/b][/size]
原内容:

<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>


[size=large][b](3)更新Spring的所有XML配置文件的头部[/b][/size]
原有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">

[b][color=red]即:将applicationContext*.xml头部中的所有的2.5修改为3.0[/color][/b]

[size=large][b](4)更新Spring MVC的所有XML配置文件的头部[/b][/size]
原有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">

[b][color=red]即:将servlet*.xml头部中的所有的2.5修改为3.0[/color][/b]

[size=large][b](5)修改所有的继承SimpleJdbcDaoSupport的文件[/b][/size]
原代码:

public class AAASDao extends SimpleJdbcDaoSupport {
...(略)
}

修改为:

public class AAASDao extends JdbcDaoSupport {
...(略)
}

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

[size=large][b](6)另外,Spring MVC基于注解的Junit测试的注解[/b][/size]
原内容

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class BaseTest extends AbstractJUnit4SpringContextTests {
...(略)
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值