<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" 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"> <!--添加包扫描--> <context:component-scan base-package="com.chentianyu.service.impl" /> <!--添加事务管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!--切记:配置数据源--> <property name="dataSource" ref="dataSource" /> </bean> <!--配置事务的切面--> <tx:advice id="myAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*select*" read-only="true"/> <tx:method name="*find*" read-only="true" /> <tx:method name="*serach*" read-only="true" /> <tx:method name="*get*" read-only="true"/> <tx:method name="*insert*" propagation="REQUIRED"/> <tx:method name="*update*" propagation="REQUIRED"/> <tx:method name="*change*" propagation="REQUIRED"/> <tx:method name="*modify*" propagation="REQUIRED"/> <tx:method name="*delete*" propagation="REQUIRED"/> <tx:method name="*drop*" propagation="REQUIRED"/> <tx:method name="*remove*" propagation="REQUIRED"/> <tx:method name="*clear*" propagation="REQUIRED"/> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <!--配置事务切入点+绑定--> <aop:config> <aop:pointcut id="mycut" expression="execution(* com.chentianyu.service.impl.*.*(..))"/> <aop:advisor advice-ref="myAdvice" pointcut-ref="mycut" /> </aop:config></beans>