ApplicationContext-Trans.xml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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"
  4. xmlns:p="http://www.springframework.org/schema/p"
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xsi:schemaLocation="http://www.springframework.org/schema/beans
  9. http://www.springframework.org/schema/beans/spring-beans.xsd
  10. http://www.springframework.org/schema/aop
  11. http://www.springframework.org/schema/aop/spring-aop.xsd
  12. http://www.springframework.org/schema/tx
  13. http://www.springframework.org/schema/tx/spring-tx.xsd
  14. http://www.springframework.org/schema/context
  15. http://www.springframework.org/schema/context/spring-context.xsd">
  16. <!--Druid连接池配置-->
  17. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
  18. <property name="driverClassName" value="${jdbc.driver}"/>
  19. <property name="url" value="${jdbc.url}"/>
  20. <property name="username" value="${jdbc.username}"/>
  21. <property name="password" value="${jdbc.password}"/>
  22. </bean>
  23. <!-- 事务管理器 -->
  24. <bean id="transactionManager"
  25. class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  26. <!-- 数据源 -->
  27. <property name="dataSource" ref="dataSource" />
  28. </bean>
  29. <!-- 通知 -->
  30. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  31. <tx:attributes>
  32. <!-- 传播行为 -->
  33. <tx:method name="save*" propagation="REQUIRED" />
  34. <tx:method name="insert*" propagation="REQUIRED" />
  35. <tx:method name="delete*" propagation="REQUIRED" />
  36. <tx:method name="update*" propagation="REQUIRED" />
  37. <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
  38. <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
  39. </tx:attributes>
  40. </tx:advice>
  41. <!-- 切面 -->
  42. <aop:config>
  43. <aop:advisor advice-ref="txAdvice"
  44. pointcut="execution(* com.em.service.*.*(..))" />
  45. </aop:config>
  46. </beans>