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/>

  • 相关阅读:
    华为软件开发云评测
    个人技术博客(α)
    结对第二次作业
    结对第一次作业----部门通
    数独设计
    2017软件工程实践第一次作业
    Alpha冲刺博客集
    个人作业——软件工程实践总结作业
    用户使用调查报告
    总结随笔(Beta)
  • 原文地址:https://www.cnblogs.com/wujianzhou/p/8401156.html
Copyright © 2011-2022 走看看