<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置事务通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="search*" read-only="true"/> <tx:method name="get*" read-only="true"/> <tx:method name="create*" read-only="false"/> <tx:method name="update*" read-only="false"/> <tx:method name="delete*" read-only="false"/> <tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/> </tx:attributes> </tx:advice> <!-- 配置切面 --> <aop:config> <!-- 配置切入点 --> <aop:pointcut id="txPointcut" expression="execution(* com.brh.p2p.admin.service.*.*(..))" /> <!-- 配置切面 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" /> </aop:config>``` 复制代码
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 开启注解事务 --> <tx:annotation-driven transaction-manager="transactionManager"/>``` 2. 在需要事务的类上添加注解如图: 复制代码