zoukankan      html  css  js  c++  java
  • 声名式事务【spring基础】

    Spring 事务机制有 声明式事务编程式事务,但是编程式事务在实际开发中不被广泛应用,仅供学习。

    Spring 在TransactionDefinition接口中定义了七个事务的传播行为:

    • propagation_requierd:如果当前没有事务,就新建一个事务,如果已存在一个事务中,加入到这个事务中,这是最常见的选择。
    • propagation_supports:支持当前事务,如果没有当前事务,就以非事务方法执行。
    • propagation_mandatory:使用当前事务,如果没有当前事务,就抛出异常。
    • propagation_required_new:新建事务,如果当前存在事务,把当前事务挂起。
    • propagation_not_supported:以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。
    • propagation_never:以非事务方式执行操作,如果当前事务存在则抛出异常。
    • propagation_nested:如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与propagation_required类似的操作

    使用aop思想配置声明式事务【横切】

        <!--配置声明式事务-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <constructor-arg ref="datasource" />
        </bean>
        <!--结合AOP实现事务的织入-->
        <!--配置事务的类-->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <!--给哪些方法配置事务-->
            <!--配置事务的传播特性,  new REQUIRED-->
            <tx:attributes>
                <tx:method name="add" propagation="REQUIRED"/>
                <tx:method name="delete" propagation="REQUIRED"/>
                <tx:method name="update" propagation="REQUIRED"/>
                <tx:method name="query" read-only="true"/>
                <tx:method name="*" propagation="REQUIRED"/>
            </tx:attributes>
        </tx:advice>
        <!--配置事务切入-->
        <aop:config>
            <aop:pointcut id="txPointCut" expression="execution(* com.wang.mapper.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
        </aop:config>
  • 相关阅读:
    word-wrap与word-break为长单词换行
    background-origin与background-clip的“区别”
    box-shadow
    你不知道的border-radius
    当document.write 遇到外联script
    getAttribute()方法的第二个参数
    Backbone.js入门教程第二版笔记(3)
    Backbone.js入门教程第二版笔记(2)
    php中的字符串常用函数(二) substr() 截取字符串
    php中类和对象的操作
  • 原文地址:https://www.cnblogs.com/IanIan/p/14353697.html
Copyright © 2011-2022 走看看