【问题标题】:Migration from Spring 2.5 to 4从 Spring 2.5 迁移到 4
【发布时间】:2014-09-20 18:28:05
【问题描述】:

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

春天 2.5.6
spring-webmvc 2.5.6
spring-webflow 2.0.7.RELEASE
休眠注释 3.4.0.GA
hibernate-commons-annotations 3.1.0.GA
休眠核心 3.3.1.GA
hibernate ejb3-persistence 1.0.2.GA

我想知道是否有办法找到与 Spring ie 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 进行查询。迁移后我可以继续使用吗?

非常感谢您提前提供的每一个提示......

【问题讨论】:

  • 我会先迁移到 3.2.9,然后再迁移到 4.x。两个专业上升是一个很大的飞跃。

标签: spring hibernate spring-mvc


【解决方案1】:

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

接下来你的PropertyPlaceHolderConfigurer 最好用&lt;context:property-placeholder /&gt; 代替,而不是普通的bean。

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

您正在使用不再存在的 spring jar,因此您需要弄清楚您需要哪些模块(从您的设置来看,至少是 jdbc 和 orm)。我真的希望你使用 Maven 来管理你的依赖项,否则你会寻找正确的相关依赖包。

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

更新后,我猜大部分仍然可以工作(或者你必须有一些其他未列出的依赖项也需要升级)。

要记住的一点是,次要的 java 版本也得到了升级,因此当升级到 Spring 4.x 时,如果您仍在使用 1.5 或更低版本,您的项目至少需要为 java 1.6。

p>

我也强烈推荐阅读the migration guide,其中包含一些有价值的信息。 (您可能希望浏览文档的历史以检索 2.5 -> 3.x 版本)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    • 2017-08-03
    相关资源
    最近更新 更多