• Spring 配置文件配置事务


    一、引入事务的头文件

    xmlns:tx="http://www.springframework.org/schema/tx"
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

    二、在applicationContext.xml中配置

     1 <!-- 定义事务管理器 -->
     2     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     3         <property name="dataSource" ref="dataSource"></property>
     4     </bean>
     5     <!-- 事务通知配置 -->
     6     <tx:advice id="txAdvice" transaction-manager="transactionManager">
     7         <tx:attributes>
     8             <tx:method name="save*" propagation="REQUIRED"/>
     9             <tx:method name="update*" propagation="REQUIRED" />
    10             <tx:method name="query*" read-only="true"/>
    11         </tx:attributes>
    12     </tx:advice>
    13     <!-- 切面配置 -->
    14     <aop:config>
    15         <aop:pointcut expression="execution(* com.tx.spring.service..*.*(..))" id="mycut"/>
    16         <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/>
    17     </aop:config>

     --------------------------------分割线---------------------------------

    如果需要采用注解形式开启事务

    则在配置文件中设置如下:

    <!-- 事务管理器的注解驱动 -->
    <tx:annotation-driven transaction-manager="txManager"/>
  • 相关阅读:
    【English】20190522
    06_Intent和IntentFilter
    05_Content Provider
    04_ Broadcast Receiver
    03_Service的绑定
    02_启动和销毁Service
    01_Activity生命周期及传递数据
    Android对应版本号
    如何在word中插入代码
    项目经验总结
  • 原文地址:https://www.cnblogs.com/cat-fish6/p/8709387.html
Copyright © 2020-2023  润新知