Spring 集成hibernate事务管理(aop实现)


  1. <bean id="transactionManager"  
  2.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  3.         <property name="sessionFactory">  
  4.             <ref bean="sFactory" />  
  5.         </property>  
  6.     </bean>  
  7.       
  8.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  
  9.         <tx:attributes>  
  10.             <tx:method name="*" propagation="REQUIRED" />  
  11.         </tx:attributes>  
  12.     </tx:advice>  
  13.   
  14.     <aop:config>  
  15.         <aop:pointcut id="tx" expression="execution(* org.ymm.services.LoginService.*(..))" />  
  16.         <aop:advisor advice-ref="txAdvice" pointcut-ref="tx" />  
  17.     </aop:config>  

Spring中进行事务管理也是利用AOP(面向切片编程)的方式,spring在通过拦截器,加载事务.

bean是创建了一个事务管理,

tx是对拦截切面的描述

aop是配置一个切面

当我们配置完了,最重要的是得到spring创建的当前CurrentSession

  1. <!-- <prop key="hibernate.current_session_context_class">thread</prop> -->  
  2.     <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext</prop>  

相关内容