升级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依赖,项目原有的依赖为 
Java代码   收藏代码
  1. spring-2.5.6.jar  
  2. spring-webmvc-2.5.6.jar  
  3. spring-test-2.5.6.jar  

增加项目新版的Spring依赖文件 
Java代码   收藏代码
  1. // aop的依赖  
  2. aopalliance-1.0.jar  
  3. // 增加spring3.1.2相关jar  
  4. org.springframework.beans-3.1.2.RELEASE.jar  
  5. org.springframework.context-3.1.2.RELEASE.jar  
  6. org.springframework.context.support-3.1.2.RELEASE.jar  
  7. org.springframework.core-3.1.2.RELEASE.jar  
  8. org.springframework.jdbc-3.1.2.RELEASE.jar  
  9. org.springframework.orm-3.1.2.RELEASE.jar  
  10. org.springframework.test-3.1.2.RELEASE.jar  
  11. org.springframework.transaction-3.1.2.RELEASE.jar  
  12. org.springframework.web-3.1.2.RELEASE.jar  
  13. org.springframework.web.servlet-3.1.2.RELEASE.jar  


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

修改为: 
Xml代码   收藏代码
  1. <listener>    
  2.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  3. </listener>  


(3)更新Spring的所有XML配置文件的头部  
原有applicationContext*.xml的头部 
Xml代码   收藏代码
  1.  <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"  
  2. xmlns:tx="http://www.springframework.org/schema/tx"  
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans  
  4.      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  5.      http://www.springframework.org/schema/context  
  6.      http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  7.      http://www.springframework.org/schema/tx  
  8.      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  

修改为: 
Xml代码   收藏代码
  1.  <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"  
  2. xmlns:tx="http://www.springframework.org/schema/tx"  
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans  
  4.      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  5.      http://www.springframework.org/schema/context  
  6.      http://www.springframework.org/schema/context/spring-context-3.0.xsd  
  7.      http://www.springframework.org/schema/tx  
  8.      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">  

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

(4)更新Spring MVC的所有XML配置文件的头部  
原有servlet*.xml的头部 
Xml代码   收藏代码
  1.  <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"  
  2. xmlns:context="http://www.springframework.org/schema/context"  
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans     
  4.      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
  5.      http://www.springframework.org/schema/context     
  6.      http://www.springframework.org/schema/context/spring-context-2.5.xsd">  

修改为: 
Xml代码   收藏代码
  1.  <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"  
  2. xmlns:context="http://www.springframework.org/schema/context"  
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans     
  4.      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
  5.      http://www.springframework.org/schema/context     
  6.      http://www.springframework.org/schema/context/spring-context-3.0.xsd">  

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

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

修改为: 
Java代码   收藏代码
  1. public class AAASDao extends JdbcDaoSupport {  
  2.    ...(略)  
  3. }  

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

(6)另外,Spring MVC基于注解的Junit测试的注解  
原内容 
Java代码   收藏代码
  1. @RunWith(SpringJUnit4ClassRunner.class)  
  2. @ContextConfiguration(locations = { "classpath:applicationContext.xml" })  
  3. public class BaseTest extends AbstractJUnit4SpringContextTests {  
  4.    ...(略)  
  5. }  

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值