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"
    4. xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    5. xmlns:aop="http://www.springframework.org/schema/aop"
    6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
    7. <!--添加包扫描-->
    8. <context:component-scan base-package="com.chentianyu.service.impl" />
    9. <!--添加事务管理器-->
    10. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    11. <!--切记:配置数据源-->
    12. <property name="dataSource" ref="dataSource" />
    13. </bean>
    14. <!--配置事务的切面-->
    15. <tx:advice id="myAdvice" transaction-manager="transactionManager">
    16. <tx:attributes>
    17. <tx:method name="*select*" read-only="true"/>
    18. <tx:method name="*find*" read-only="true" />
    19. <tx:method name="*serach*" read-only="true" />
    20. <tx:method name="*get*" read-only="true"/>
    21. <tx:method name="*insert*" propagation="REQUIRED"/>
    22. <tx:method name="*update*" propagation="REQUIRED"/>
    23. <tx:method name="*change*" propagation="REQUIRED"/>
    24. <tx:method name="*modify*" propagation="REQUIRED"/>
    25. <tx:method name="*delete*" propagation="REQUIRED"/>
    26. <tx:method name="*drop*" propagation="REQUIRED"/>
    27. <tx:method name="*remove*" propagation="REQUIRED"/>
    28. <tx:method name="*clear*" propagation="REQUIRED"/>
    29. <tx:method name="*" propagation="SUPPORTS" />
    30. </tx:attributes>
    31. </tx:advice>
    32. <!--配置事务切入点+绑定-->
    33. <aop:config>
    34. <aop:pointcut id="mycut" expression="execution(* com.chentianyu.service.impl.*.*(..))"/>
    35. <aop:advisor advice-ref="myAdvice" pointcut-ref="mycut" />
    36. </aop:config>
    37. </beans>