applicationContext-transaction.xml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  8. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
  9. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
  10. <!-- 配置一个事务管理器 -->
  11. <bean id="transactionManager"
  12. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  13. <!-- 数据源 -->
  14. <property name="dataSource" ref="dataSource" />
  15. </bean>
  16. <!-- 配置通知 -->
  17. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  18. <tx:attributes>
  19. <!-- 传播行为 -->
  20. <tx:method name="save*" propagation="REQUIRED" />
  21. <tx:method name="insert*" propagation="REQUIRED" />
  22. <tx:method name="add*" propagation="REQUIRED" />
  23. <tx:method name="create*" propagation="REQUIRED" />
  24. <tx:method name="delete*" propagation="REQUIRED" />
  25. <tx:method name="update*" propagation="REQUIRED" />
  26. <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
  27. <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
  28. <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
  29. </tx:attributes>
  30. </tx:advice>
  31. <!-- 配置切面 -->
  32. <aop:config>
  33. <aop:advisor advice-ref="txAdvice"
  34. pointcut="execution(* com.itheima.service.*.*(..))" />
  35. </aop:config>
  36. </beans>