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

参考:
Spring AOP中pointcut expression表达式解析 及匹配多个条件 http://www.cnblogs.com/qinyubin/p/4075466.html
Spring事务配置多个切点,即多个execution http://blog.csdn.net/z_dendy/article/details/9447857




<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>
    <!--
         *:匹配任何数量字符;
         ..:匹配任何数量字符的重复,如在类型模式中匹配任何数量子包;而在方法参数模式中匹配任何数量参数。
         +:匹配指定类型的子类型;仅能作为后缀放在类型模式后边。
    -->

猜你喜欢

转载自panyongzheng.iteye.com/blog/2298122