spring的事务理解

来源:互联网 发布:达内软件培训费用 编辑:程序博客网 时间:2024/05/18 20:53

搜集了一些网上的介绍,这是我对spring事务的理解:

spring是在service中事务管理,是当他调用service中的一个方法的时候 就会开启一个事务,直到你执行完这个方法,才会commit。所以只要其中有一个方法失败都会回滚。

就是说配置到方法上,但管理事务在service中

<tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="*" propagation="REQUIRED"/></tx:attributes></tx:advice><aop:config><aop:pointcut id="interceptorPointCuts"expression="execution(* com.*.service.*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts"/></aop:config>
<tx:method name="*" propagation="REQUIRED"/>这句是将所有的方法都走事务,当然也可以自己定义些,可使用通配符。

<aop:pointcut id="interceptorPointCuts"expression="execution(* com.*.service.*.*(..))"/> 这句是将事务管理应用到service上,具体表达式根据自己建的包使用通配符来创建,最后的*.*是到某个类下的某个方法,括号是匹配任意参数。

0 0
原创粉丝点击