歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Spring 集成hibernate事務管理(aop實現)

Spring 集成hibernate事務管理(aop實現)

日期:2017/3/1 10:18:16   编辑:Linux編程
  1. <bean id="transactionManager"
  2. class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  3. <property name="sessionFactory">
  4. <ref bean="sFactory" />
  5. </property>
  6. </bean>
  7. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  8. <tx:attributes>
  9. <tx:method name="*" propagation="REQUIRED" />
  10. </tx:attributes>
  11. </tx:advice>
  12. <aop:config>
  13. <aop:pointcut id="tx" expression="execution(* org.ymm.services.LoginService.*(..))" />
  14. <aop:advisor advice-ref="txAdvice" pointcut-ref="tx" />
  15. </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>
Copyright © Linux教程網 All Rights Reserved