日期:2014-05-17  浏览次数:20784 次

求助 spring 接管hebernate 事物 一直失败
Exception in thread "main" org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
at com.wz.dao.basic.BasicDao.executeQuery(BasicDao.java:34)
at com.wz.test.Test.main(Test.java:22)

applicationContext.xml 文件配置

<?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: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-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>



<bean id="userDaoImpl" class="com.wz.dao.impl.UserDaoImpl">

<property name="sessionFactory" ref="sessionFactory"/>
</bean>
 
 <!-- 配置Hibernate的局部事物管理器 -->
     <bean id="transactionManager"
             class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
         <ref local="sessionFactory" />
        </property>
    </bean>
    
     <!-- 配置事物切面Bean -->
     <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />