zoukankan      html  css  js  c++  java
  • Spring基于XML的声明式事务控制

     1 <!-- spring中基于XML的声明式事务控制配置步骤
     2         1、配置事务管理器
     3         2、配置事务的通知
     4                 此时我们需要导入事务的约束 tx名称空间和约束,同时也需要aop的
     5                 使用tx:advice标签配置事务通知
     6                     属性:
     7                         id:给事务通知起一个唯一标识
     8                         transaction-manager:给事务通知提供一个事务管理器引用
     9         3、配置AOP中的通用切入点表达式
    10         4、建立事务通知和切入点表达式的对应关系
    11         5、配置事务的属性
    12                是在事务的通知tx:advice标签的内部
    13 
    14      -->
    15     <!-- 配置事务管理器 -->
    16     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    17         <property name="dataSource" ref="dataSource"></property>
    18     </bean>
    19 
    20     <!-- 配置事务的通知-->
    21     <tx:advice id="txAdvice" transaction-manager="transactionManager">
    22         <!-- 配置事务的属性
    23                 isolation:用于指定事务的隔离级别。默认值是DEFAULT,表示使用数据库的默认隔离级别。
    24                 propagation:用于指定事务的传播行为。默认值是REQUIRED,表示一定会有事务,增删改的选择。查询方法可以选择SUPPORTS。
    25                 read-only:用于指定事务是否只读。只有查询方法才能设置为true。默认值是false,表示读写。
    26                 timeout:用于指定事务的超时时间,默认值是-1,表示永不超时。如果指定了数值,以秒为单位。
    27                 rollback-for:用于指定一个异常,当产生该异常时,事务回滚,产生其他异常时,事务不回滚。没有默认值。表示任何异常都回滚。
    28                 no-rollback-for:用于指定一个异常,当产生该异常时,事务不回滚,产生其他异常时事务回滚。没有默认值。表示任何异常都回滚。
    29         -->
    30         <tx:attributes>
    31             <tx:method name="*" propagation="REQUIRED" read-only="false"/>
    32             <tx:method name="find*" propagation="SUPPORTS" read-only="true"></tx:method>
    33         </tx:attributes>
    34     </tx:advice>
    35 
    36     <!-- 配置aop-->
    37     <aop:config>
    38         <!-- 配置切入点表达式-->
    39         <aop:pointcut id="pt1" expression="execution(* com.fanxian.service.impl.*.*(..))"></aop:pointcut>
    40         <!--建立切入点表达式和事务通知的对应关系 -->
    41         <aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"></aop:advisor>
    42     </aop:config>
  • 相关阅读:
    使用 libevent 和 libev 提高网络应用性能
    An existing connection was forcibly closed by the remote host
    各种浏览器的兼容css
    vs输出窗口,显示build的时间
    sass
    网站设置404错误页
    List of content management systems
    css footer not displaying at the bottom of the page
    强制刷新css
    sp_executesql invalid object name
  • 原文地址:https://www.cnblogs.com/SanChauncy/p/12493383.html
Copyright © 2011-2022 走看看