`
chuanlhc
  • 浏览: 69715 次
  • 性别: Icon_minigender_1
  • 来自: 广州
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

从Spring 3.0升级到Spring 3.1

 
阅读更多

几天前我想,是时候将我的项目升级到 Spring 3.1 了,毕竟 3.1 版本已经经过几个 bug 修复版后足够稳定了。

升级到 Spring 3.1 是非常简单的,只需要更新 Maven 的版本号然后重新构建即可:

  1. <dependency>  
  2.     <groupId>org.springframework</groupId>  
  3.     <artifactId>spring-core</artifactId>  
  4.     <version>3.1.2.RELEASE</version>  
  5. </dependency> 

重新编译后你会发现报了很多新的废弃类的警告,例如 XmlBeanFactory 已经改用 DefaultListableBeanFactory 替代:

  1. Resource resource = new ClassPathResource("example2.xml");  
  2. return new XmlBeanFactory(resource); 

需要改为:

  1. Resource resource = new ClassPathResource("example2.xml");  
  2. DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();  
  3. BeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);  
  4. reader.loadBeanDefinitions(resource); 

完整的被废弃的类的列表请看

http://www.osctools.net/uploads/apidocs/Spring-3.1.1/deprecated-list.html

接下来是需要将 Spring 的 XML Schema 从 3.0 改为 3.1,如:

  1. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 

改为:

  1. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 

最简单的方法就是在 Eclipse 里使用全局替换将 -3.0.xsd 改为 -3.1.xsd,但替换之前最好还是检查一下。

更新 Schema 的目的是为了更多的使用新版本 Spring 的新特性。

原文链接:http://www.oschina.net/question/54100_63771

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics