zoukankan      html  css  js  c++  java
  • 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"/>
  • 相关阅读:
    Tomcat虚拟目录的映射方式
    Linux常用命令
    java断点调试
    破解MyEclipse
    JS判断浏览器
    css3 box-sizing详解。
    this-使用call . apply
    this-内部函数
    this-对象方法调用
    this-纯函数
  • 原文地址:https://www.cnblogs.com/cat-fish6/p/8709387.html
Copyright © 2011-2022 走看看