zoukankan      html  css  js  c++  java
  • spring声明式事务的配置

    spring声明式事务配置

    1、XML配置

    (1)配置平台事务管理器
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
    </bean>

     

    (2)配置事务通知
    <tx:advice id="txAdvice"
    transaction-manager="transactionManager">
    <tx:attributes>
    <!--对方法级别设置事务的隔离级别、传播行为-->
    <!--设置了默认的隔离级别-->
    <!--添加-->
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="create*" propagation="REQUIRED" />
    <!--删除-->
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="remove*" propagation="REQUIRED" />
    <!--修改-->
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="modify*" propagation="REQUIRED" />
    <!--查询-->
    <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
    <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
    <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
    </tx:attributes>

     

    (3)配置aop
        <aop:config>
    <!-- 这使用的是Spring AOP的实现 -->
    <!-- advice-ref:指定advice增强类 -->
    <!-- pointcut:指定切点 -->
    <aop:advisor advice-ref="txAdvice"
    pointcut="execution(* *..*.*ServiceImpl.*(..))" />
    </aop:config>

     

    2、混合配置

    (1)开启事务注解
        <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!-- 配置事务注解驱动 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

     

    (2)用@Transactional注解标注要使用事务的类或者方法

     

    3、纯注解配置

    @EnableTransactionManagement

     

  • 相关阅读:
    [置顶网]POWER 9为云与智能打造强大引擎
    [丁香医生]百亿保健帝国权健,和它阴影下的中国家庭---保存一下
    【菜鸟】RESTful 架构详解
    搞笑三问
    [置顶网] 世界服务器出货量
    [51CTO]新说MySQL事务隔离级别!
    Win2008r2 由ESXi 转换到 HyperV的处理过程
    Postgresql迁移数据文件存放位置
    极简版 卸载 home 扩充 根分区--centos7 xfs 文件格式
    CentOS下面磁盘扩容处理
  • 原文地址:https://www.cnblogs.com/BonnieWss/p/12217283.html
Copyright © 2011-2022 走看看