简体   繁体   English

从Spring 2.5迁移到4

[英]Migration from Spring 2.5 to 4

I want to migrate my project from Spring 2.5 to Spring 4.1 我想将项目从Spring 2.5迁移到Spring 4.1
The old versions of Spring and Hibernate jars used in my project are: 我的项目中使用的Spring和Hibernate jar的旧版本是:

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

I wanted to know if there is a way I could find the latest version of Hibernate which is compatible with Spring ie 4.1 我想知道是否有办法找到与Spring即4.1兼容的最新版本的Hibernate。
Secondly I would like to know what configuration changes should I make in applicationContext.xml. 其次,我想知道我应该在applicationContext.xml中进行哪些配置更改。 My applicationContext looks like this 我的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>

and at last, I'm using HibernateTemplate for my queries. 最后,我使用HibernateTemplate进行查询。 Can I continue using the same after migration.? 迁移后可以继续使用相同的功能吗?

Many thanks for every tip in advance... 非常感谢您提前提出的每条提示...

In theory it should be a drop in replace. 从理论上讲,它应该是替代品。 However before migrating I strongly suggest you first change the xml files you use. 但是,在迁移之前,我强烈建议您先更改您使用的xml文件。 Currently you have versioned xsd in your headers ie spring-beans-2.5.xsd remove the versions ie spring-beans.xsd . 当前,您在标头(即spring-beans-2.5.xsd中对xsd进行了版本控制,请删除版本(即spring-beans.xsd

Next your PropertyPlaceHolderConfigurer is best replaced with a <context:property-placeholder /> instead of the plain bean. 接下来,最好用<context:property-placeholder />而不是普通bean替换PropertyPlaceHolderConfigurer

The hibernate integration has been highly refactored for Hibernate4 so I would stick with the latest hibernate 3.x version (3.6.10) and make that a separate migration (to either plain Hibernate 4 or JPA). Hibernate集成已对Hibernate4进行了高度重构,因此我会坚持使用最新的hibernate 3.x版本(3.6.10),并进行单独的迁移(迁移至普通Hibernate 4或JPA)。 If you have it running again then upgrade to the latest hibernate version (4.3.6) as that will require some code changes and depending on the amount of code can hurt considerably. 如果再次运行它,则升级到最新的休眠版本(4.3.6),因为这将需要进行一些代码更改,并且取决于代码量,这可能会造成很大的伤害。

You are using the spring jar which doesn't exists anymore so you need to figure out which modules you need (judging from your setup at least jdbc and orm). 您正在使用的弹簧罐已经不存在了,因此您需要弄清楚需要哪些模块(从设置中至少从jdbc和orm来看)。 I really hope that you are using Maven to manage your dependencies else you are in for a treat looking for the correct bundle of related dependencies. 我真的希望您使用Maven来管理您的依赖项,否则您将需要寻找正确的相关依赖项捆绑包。

Spring Web Flow will also require an upgrade to the latest 2.4.0, not sure if that is a drop in replacement though. Spring Web Flow也将需要升级到最新的2.4.0,但是不确定这是否是替代产品。

After updating I guess most of it will still work (or you must have some other unlisted dependencies here that also require an upgrade). 更新后,我猜它大部分仍然可以使用(或者您在这里还必须具有一些其他未列出的依赖项,这些依赖项也需要升级)。

One thing to keep in mind is that also the minor java versions got upgraded so when upgrading to Spring 4.x your project needs to be at least java 1.6 if you are still on 1.5 or lower it will not work. 要记住的一件事是,次要的Java版本也进行了升级,因此,如果您仍在1.5或更低版本上,则在升级到Spring 4.x时,您的项目需要至少为Java 1.6。

I also strongly recommend reading the migration guide which contains some valuable information. 我也强烈建议您阅读迁移指南 ,其中包含一些有价值的信息。 (You might want to skim through the history of the document to retrieve the 2.5 -> 3.x version). (您可能需要浏览文档的历史记录以检索2.5-> 3.x版本)。

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

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