繁体   English   中英

从Spring 2.5迁移到4

[英]Migration from Spring 2.5 to 4

我想将项目从Spring 2.5迁移到Spring 4.1
我的项目中使用的Spring和Hibernate jar的旧版本是:

春天2.5.6
弹簧webmvc 2.5.6
spring-webflow 2.0.7。发布
休眠注释3.4.0.GA
休眠公共注释3.1.0.GA
休眠核心3.3.1.GA
休眠ejb3-persistence 1.0.2.GA

我想知道是否有办法找到与Spring即4.1兼容的最新版本的Hibernate。
其次,我想知道我应该在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进行查询。 迁移后可以继续使用相同的功能吗?

非常感谢您提前提出的每条提示...

从理论上讲,它应该是替代品。 但是,在迁移之前,我强烈建议您先更改您使用的xml文件。 当前,您在标头(即spring-beans-2.5.xsd中对xsd进行了版本控制,请删除版本(即spring-beans.xsd

接下来,最好用<context:property-placeholder />而不是普通bean替换PropertyPlaceHolderConfigurer

Hibernate集成已对Hibernate4进行了高度重构,因此我会坚持使用最新的hibernate 3.x版本(3.6.10),并进行单独的迁移(迁移至普通Hibernate 4或JPA)。 如果再次运行它,则升级到最新的休眠版本(4.3.6),因为这将需要进行一些代码更改,并且取决于代码量,这可能会造成很大的伤害。

您正在使用的弹簧罐已经不存在了,因此您需要弄清楚需要哪些模块(从设置中至少从jdbc和orm来看)。 我真的希望您使用Maven来管理您的依赖项,否则您将需要寻找正确的相关依赖项捆绑包。

Spring Web Flow也将需要升级到最新的2.4.0,但是不确定这是否是替代产品。

更新后,我猜它大部分仍然可以使用(或者您在这里还必须具有一些其他未列出的依赖项,这些依赖项也需要升级)。

要记住的一件事是,次要的Java版本也进行了升级,因此,如果您仍在1.5或更低版本上,则在升级到Spring 4.x时,您的项目需要至少为Java 1.6。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM