applicationcontext-tx.xml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  8. http://www.springframework.org/schema/context
  9. http://www.springframework.org/schema/context/spring-context-3.0.xsd
  10. http://www.springframework.org/schema/aop
  11. http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  12. http://www.springframework.org/schema/tx
  13. http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  14. <!-- 事务管理器(声明式事务) -->
  15. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  16. <property name="dataSource" ref="dataSource" />
  17. </bean>
  18. <!-- 启动事务注解(方式1:注解方式) -->
  19. <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
  20. <!-- 事务通知(方式2:XML事务管理) -->
  21. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  22. <tx:attributes>
  23. <tx:method name="detail*" propagation="SUPPORTS" />
  24. <tx:method name="visit*" propagation="SUPPORTS" />
  25. <tx:method name="get*" propagation="SUPPORTS" />
  26. <tx:method name="find*" propagation="SUPPORTS" />
  27. <tx:method name="check*" propagation="SUPPORTS" />
  28. <tx:method name="list*" propagation="SUPPORTS" />
  29. <tx:method name="*" propagation="REQUIRED" rollback-for="exception" />
  30. </tx:attributes>
  31. </tx:advice>
  32. <!-- AOP配置 -->
  33. <aop:config>
  34. <!-- 定义一个切入点 -->
  35. <aop:pointcut id="txoperation" expression="execution(* com.xxl.service.imp.*.*(..))" />
  36. <!-- 切入点事务通知 -->
  37. <aop:advisor pointcut-ref="txoperation" advice-ref="txAdvice" />
  38. </aop:config>
  39. </beans>