<!--装配事务管理器类对象,通过构造方法传入数据源-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<constructor-arg ref="dataSource"/>
</bean>
<!--结合AOP执行事务的注入-->
<!--配置事务通知-->
<tx:advice id="transactionInterceptor" transaction-manager="transactionManager">
<!--给哪些方法配置事务通知-->
<tx:attributes>
<tx:method name="addUser"/>
<tx:method name="selectUser"/>
<tx:method name="deleteUser"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--配置aop切入点进行方法事务通知-->
<aop:config>
<!--切入点-->
<aop:pointcut id="pointcut" expression="execution(* wsh.mapper.*.*(..))"/>
<aop:advisor advice-ref="transactionInterceptor" pointcut-ref="pointcut"/>
</aop:config>
</beans>

注意:一个测试类中执行一个方法在方法里的所有数据库操作为一次事务,多个操作是多个事务,
事务是实现事务内多个sql语句一并执行,有一个错误全部回滚执行失败,有全对则对一错全错特点
posted on 2022-05-28 20:56  唔噗噗噗  阅读(44)  评论(0)    收藏  举报