2014-09-20 61 views
1

我要迁移从Spring 2.5中我的项目到Spring 4.1
春天的旧版本和Hibernate在我的项目中使用的罐子:迁移距离Spring 2.5至4

春天2.5.6
弹簧webmvc 2.5.6
弹簧的Webflow 2.0.7.RELEASE
休眠的注解3.4.0.GA
冬眠-公地注解3.1.0.GA
冬眠核3.3.1.GA
冬眠ejb3-持久性1.0.2.GA

我想知道是否有方法可以找到与Spring兼容的Hibernate的最新版本,即4.1
其次,我想知道我应该在applicationContext.xml中进行哪些配置更改。 我的applicationContext看起来像这样

<?xml version="1.0" encoding="UTF-8"?> 
<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:aop="http://www.springframework.org/schema/aop" 
     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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 

    <bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
      <property name="location" value="classpath:jdbc.properties"/> 
      <property name="ignoreUnresolvablePlaceholders" value="true"/> 
    </bean> 

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
     <property name="driverClassName" value="${dataSource.driverClassName}"></property> 
     <property name="url" value="${dataSource.url}"></property> 
     <property name="username" value="${dataSource.username}"></property> 
     <property name="password" value="${dataSource.password}"></property> 
     <property name="initialSize" value="1"></property> 
     <property name="maxActive" value="10"></property> 
     <property name="maxIdle" value="14"></property> 
     <property name="minIdle" value="2"></property> 
     <property name="maxWait" value="15000"></property> 
     <property name="validationQuery" value="SELECT 1"></property> 
     <property name="minEvictableIdleTimeMillis" value="5000"></property> 
     <property name="testOnBorrow" value="true"></property> 
     <property name="testOnReturn" value="true"></property> 
     <property name="removeAbandoned" value="true"></property> 
     <property name="removeAbandonedTimeout" value="5"></property> 
    </bean> 

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 
     <!-- Limit uploads to small (5KB) files for this sample --> 
     <property name="maxUploadSize" value="809000" /> 
    </bean> 

    <!-- Default Connection --> 
    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="configLocation"> 
      <value>/WEB-INF/hibernate.cfg.xml</value> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${dataSource.dialect}</prop> 
       <prop key="hibernate.default_batch_fetch_size">30</prop> 
       <prop key="hibernate.jdbc.fetch_size">20</prop> 
       <prop key="org.hibernate.cache">info</prop> 
       <prop key="org.hibernate.transaction">debug</prop> 
       <prop key="hibernate.jdbc.batch_size">100</prop> 
       <prop key="hibernate.show_sql">false</prop> 
       <prop key="hibernate.use_sql_comments">true</prop> 
       <prop key="hibernate.max_fetch_depth">3</prop> 
       <prop key="hibernate.jdbc.batch_versioned_data">true</prop> 
      </props> 
     </property> 
     <property name="schemaUpdate" value="false" /> 

    </bean> 

    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 

    <tx:annotation-driven transaction-manager="txManager"/> 

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
     <property name="dataSource" ref="dataSource"/> 
    </bean> 

<bean id="baseService" abstract="true" lazy-init="true"> 
     <property name="jdbcTemplate" ref="jdbcTemplate"/> 
     <property name="dataSource" ref="dataSource"/> 
     <property name="sessionFactory" ref="sessionFactory"/> 

    </bean> 
</beans> 

,最后,我用的HibernateTemplate我的查询。我可以在迁移后继续使用它吗?

非常感谢提前每个秘诀...

+0

我会先迁移到3.2.9,然后迁移到4.x.两个专业是一个很大的飞跃。 – soulcheck 2014-09-20 18:43:07

回答

2

理论上它应该是一个下降更换。但是,在迁移之前,我强烈建议您首先更改您使用的xml文件。目前,您的头文件中已经版本化了xsd,即spring-beans-2.5.xsd删除了版本,即spring-beans.xsd

下一页您PropertyPlaceHolderConfigurer最好用<context:property-placeholder />而不是普通的豆取代。我们将坚持使用最新的hibernate 3.x版本(3.6.10),并将其作为单独的迁移(无论是普通的Hibernate 4还是JPA)。如果您再次运行它,请升级到最新的hibernate版本(4.3.6),因为这需要进行一些代码更改,并且取决于代码数量会受到相当大的影响。

您使用的是弹簧罐子它这样做,你需要搞清楚哪些模块您需要(从您的设置至少JDBC和ORM判断)不再存在。我真的希望你正在使用Maven来管理你的其他依赖,以寻找正确的相关依赖包。

Spring Web Flow的也需要升级到最新的2.4.0,不知道这是在更换下降,但。

更新后,我想大多数将仍然有效(或您必须在这里一些其他未列明的依赖性也需要升级)。

有一点要记住的是,还未成年的Java版本升级了所以升级到春天4.x中您的项目时,需要至少Java 1.6的,如果你仍然在1.5或降低它不会工作。

我也强烈建议阅读the migration guide其中包含了一些有价值的信息。 (您可能需要浏览文档的历史记录以检索2.5 - > 3.x版本)。