zoukankan      html  css  js  c++  java
  • spring事务的两种配置方式,不是很理解。先放到这里。

    一、

    <!-- 事务管理 通知 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <!-- 对insert,update,delete 开头的方法进行事务管理,只要有异常就回滚 -->
                <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
                <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
                <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
                <tx:method name="fileUpload" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
                <tx:method name="fileDownload" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
                <!-- select,count开头的方法,开启只读,提高数据库访问性能 -->
                <tx:method name="select*" read-only="true"/>
                <tx:method name="count*" read-only="true"/>
                <!-- 对其他方法 使用默认的事务管理 -->
                <tx:method name="*"/>
            </tx:attributes>
        </tx:advice>
    
        <!-- 事务 aop 配置 -->
        <aop:config>
            <aop:pointcut id="serviceMethods" expression="(execution(* org.szfzx.siss.**.service.**.**.*(..)))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
        </aop:config>
    
        <!-- 配置使Spring采用CGLIB代理 -->
        <aop:aspectj-autoproxy proxy-target-class="true"/>
    
        <!-- 启用对事务注解的支持 -->
        <tx:annotation-driven transaction-manager="transactionManager"/>


    二、

    <!-- 事务 aop 配置 -->
        <aop:config>
            <aop:pointcut id="serviceMethods1" expression="execution(* org.szfzx.siss.**.service.**.**.update*(..))"/>
            <aop:pointcut id="serviceMethods2" expression="execution(* org.szfzx.siss.**.service.**.**.insert*(..))"/>
            <aop:pointcut id="serviceMethods3" expression="execution(* org.szfzx.siss.**.service.**.**.delete*(..))"/>
            <aop:pointcut id="serviceMethods4" expression="execution(* org.szfzx.siss.**.service.**.**.fileUpload(..))"/>
            <aop:pointcut id="serviceMethods5" expression="execution(* org.szfzx.siss.**.service.**.**.fileDownload(..))"/>
    
            <aop:advisor pointcut-ref="serviceMethods1" advice-ref="txAdvice"/>
            <aop:advisor pointcut-ref="serviceMethods2" advice-ref="txAdvice"/>
            <aop:advisor pointcut-ref="serviceMethods3" advice-ref="txAdvice"/>
            <aop:advisor pointcut-ref="serviceMethods4" advice-ref="txAdvice"/>
            <aop:advisor pointcut-ref="serviceMethods5" advice-ref="txAdvice"/>
        </aop:config>
        
        <!-- 事务管理 通知 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">  
            <tx:attributes>  
                <tx:method name="*" rollback-for="java.lang.Exception" />  
           </tx:attributes>  
        </tx:advice>  
  • 相关阅读:
    httpclient的maven依赖
    阿里云maven仓库镜像
    log4j2在webapp项目中的配置
    web.xml中的filter标签
    mybatis在xml文件中处理大于号小于号的方法
    javaweb(三十八)——mysql事务和锁InnoDB(扩展)
    javaweb(三十八)——事务
    javaweb(三十七)——获得MySQL数据库自动生成的主键
    javaweb学习总结(三十六)——使用JDBC进行批处理
    JavaWeb(三十五)——使用JDBC处理Oracle大数据
  • 原文地址:https://www.cnblogs.com/airduce/p/8625600.html
Copyright © 2011-2022 走看看