0
点赞
收藏
分享

微信扫一扫

spring配置事物的方式:注解和aop配置



<tx:annotation-driven transaction-manager="springTransactionManager" proxy-target-class="true"/>


<!-- 定义事务的管理者 -->
<tx:advice id="txAdvice" transaction-manager="springTransactionManager">
<!-- 定义使用事务的方法特征行为 -->
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.RuntimeException"/>
<tx:method name="insert*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.RuntimeException"/>
<tx:method name="update*" propagation="REQUIRED" read-only="false"
rollback-for="java.lang.RuntimeException"/>

<tx:method name="find*" propagation="SUPPORTS"/>
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="select*" propagation="SUPPORTS"/>
<tx:method name="query*" propagation="SUPPORTS"/>

<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>

<!-- 配置事务切入点 -->
<aop:config>
<!--把事务控制在Service层-->
<aop:pointcut id="bussinessService"
expression="execution(public * com.pandy..atomikos.service..*Service*.*(..))"/>
<!-- 指定bussinessService切入点应用txAdvice处理器,即该切入点的所有符合特征的方法均具备了事务性 -->
<aop:advisor pointcut-ref="bussinessService" advice-ref="txAdvice"/>
</aop:config>
<!--
*:匹配任何数量字符;
..:匹配任何数量字符的重复,如在类型模式中匹配任何数量子包;而在方法参数模式中匹配任何数量参数。
+:匹配指定类型的子类型;仅能作为后缀放在类型模式后边。
-->

举报

相关推荐

0 条评论