zoukankan      html  css  js  c++  java
  • spring事务管理

    spring 事务运行时异常默认回滚

    spring事务检查性异常不会回滚,如果需要回滚,添加rollback-for="抛出的异常类"

    如:<tx:method name="transfer" rollback-for="java.io.FileNotFoundException" />

    (1)声明式事务

    在applicationContext.xml中加入

    <!-- 声明式事务配置开始 -->
        <bean id="transactionManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource" />
        </bean>
    
        <!-- 配置事务增强处理Bean,指定事务管理器 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
    
            <tx:attributes>
    
                <tx:method name="get*" read-only="true" />
                <tx:method name="transfer" />
    
                <tx:method name="*" />
            </tx:attributes>
        </tx:advice>
    
        <aop:config>
            <aop:pointcut id="myPointcut" expression="execution(* com.service.impl.*.*(..))" />
    
            <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
    
        </aop:config>


    (2)注解事务

    在加入事务的方法上添加注解(@Transactional)

    在applicationContext.xml中添加<tx:annotation-driven/>

  • 相关阅读:
    MySQL不支持的特性
    MySQL查询执行路径
    MySQL索引
    索引的选择性
    MySQL学习笔记_时间,多表更新,数据库元数据
    PowerDesigner 小技巧
    linux下清空文件内容
    mysql跟踪sql
    Navicat For Mysql快捷键
    PHP 配置多站点多目录
  • 原文地址:https://www.cnblogs.com/wujianzhou/p/8401156.html
Copyright © 2011-2022 走看看