spring hiberante 集成出现异常 java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImpleme...

本文详细解析了在集成Spring和Hibernate时版本不匹配导致的异常问题,具体阐述了如何通过调整配置文件来解决由事务管理器不兼容引发的错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现如题的异常是由于hibernate和spring集成时的的版本不一致所导致。

如下面,所示,如果你用的hibneate 4.0及以上版本,那么将会报错,因为这里用的事务管理是hibernate 3.并非缺少什么jar包。

org.springframework.orm.hibernate3.HibernateTransactionManager 

 

<?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:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.2.xsd
               http://www.springframework.org/schema/tx
               http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
               http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
               ">
    
    <!-- 配置一个SessionFactory,使用我们自己写的工具类来获取SessionFactory -->
    <bean id="mysessionFactory" class="com.amos.spring.dao.HibernateUtil" factory-method="getFactory">
    </bean>
    <!-- 配置一个使用HiberanteTemplate对象 -->
    <bean id="myTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory" ref="mysessionFactory"></property>
    </bean>
    <!-- 配置一个使用hibernateTemplate的dao-->         
    <bean id="accountDao"    class="com.amos.spring.dao.AccountDaoByHibernateTemplate">
    <property name="template" ref="myTemplate"></property>
    </bean>
    <bean id="transferService" class="com.amos.spring.service.TransferServiceImpl2">
    <property name="accountDao" ref="accountDao"></property>
    </bean>
    
    <!-- 配置事务管理 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <!-- 事务管理器作用于哪个SessionFactory -->
    <property name="sessionFactory" ref="mysessionFactory"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值