我想将我的项目从Spring2.5迁移到Spring4.1
在我的项目中使用的Spring和Hibernate jars的旧版本是:
春季2.5.6
spring-webmvc 2.5.6
弹簧-webflow 2.0.7
hibernate-注释3.4.0.GA
hibernate-共用-注释3.1.0.GA
hibernate-核心3.3.1.GA
hibernate ejb3-持久性1.0.2.GA
我想知道是否有办法找到与SpringIE4.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进行查询。我可以在移民后继续使用吗?
非常感谢提前给出的每一条建议..。
发布于 2014-09-22 09:46:27
从理论上讲,这应该是替换量的下降。然而,在迁移之前,我强烈建议您首先更改使用的xml文件。目前,在标头中已经有了版本化的xsd,即spring-beans-2.5.xsd
,删除版本,即spring-beans.xsd
。
接下来,最好将PropertyPlaceHolderConfigurer
替换为<context:property-placeholder />
,而不是普通bean。
hibernate集成对于Hibernate4来说是高度重构的,所以我将坚持使用最新的hibernate 3.x版本(3.6.10),并将其单独迁移到普通Hibernate 4或JPA。如果您让它再次运行,那么升级到最新的hibernate版本(4.3.6),因为这将需要一些代码更改,并且取决于代码的数量可能会造成很大的伤害。
您正在使用不再存在的spring,因此需要确定您需要哪些模块(从设置(至少从jdbc和orm)判断)。我真的希望您正在使用Maven来管理您的依赖关系,否则,您将需要寻找正确的相关依赖包。
Spring还需要升级到最新的2.4.0,但不确定这是否是替换量的下降。
在更新之后,我猜大部分都还能工作(或者您必须在这里有一些其他未列出的依赖项,这些依赖项也需要升级)。
需要记住的一点是,次要的java版本也得到了升级,所以当升级到Spring4.x时,您的项目至少需要是Java1.6,如果您仍然使用1.5或更低的版本,它将无法工作。
我还强烈建议阅读包含一些有价值信息的迁移指南。(您可能需要浏览文档的历史记录,以检索2.5 -> 3.x版本)。
https://stackoverflow.com/questions/25952009
复制相似问题