Spring中 PROPAGATION_REQUIRED 解释
转自:https://blog.csdn.net/bigtree_3721/article/details/53966617
事务传播行为种类
Spring在TransactionDefinition接口中规定了7种类型的事务传播行为,
它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播:
事务传播行为类型
|
事务传播行为类型 |
说明 |
|
PROPAGATION_REQUIRED |
如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中。这是最常见的选择。 |
|
PROPAGATION_SUPPORTS |
支持当前事务,如果当前没有事务,就以非事务方式执行。 |
|
PROPAGATION_MANDATORY |
使用当前的事务,如果当前没有事务,就抛出异常。 |
|
PROPAGATION_REQUIRES_NEW |
新建事务,如果当前存在事务,把当前事务挂起。 |
|
PROPAGATION_NOT_SUPPORTED |
以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。 |
|
PROPAGATION_NEVER |
以非事务方式执行,如果当前存在事务,则抛出异常。 |
|
PROPAGATION_NESTED |
如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则执行与PROPAGATION_REQUIRED类 似的操作。 |
实例为
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd"
- default-autowire="byName">
- <import resource="classpath*:spring/spring-config-dao.xml" />
- <context:component-scan base-package="com.letv.*.manager" />
- <aop:aspectj-autoproxy proxy-target-class="true" />
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource"/>
- </bean>
- <tx:advice id="txAdvice" transaction-manager="transactionManager">
- <tx:attributes>
- <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
- <tx:method name="save*" propagation="REQUIRED"/>
- <tx:method name="insert*" propagation="REQUIRED"/>
- <tx:method name="batchSave*" propagation="REQUIRED"/>
- <tx:method name="update*" propagation="REQUIRED"/>
- <tx:method name="cancelOrder" propagation="REQUIRED"/>
- <tx:method name="*" propagation="SUPPORTS" read-only="true" />
- </tx:attributes>
- </tx:advice>
- <aop:config>
- <aop:pointcut id="managers" expression="execution(* com.thb.*.manager..*.*(..)) "/>
- <aop:advisor advice-ref="txAdvice" pointcut-ref="managers"/>
- </aop:config>
- </beans>
上面配置文件意思是调用 com.thb.下面的任何的任何manager类里的以query,save, update等开头的方法和 cancelorder方法时,在方法层面上事务级别是required,而调用这些manager的别的方法则是support级别。
比如 在下面的 com.letv.ofc.manager.impl.updateStrategyResult() 方法中,又调用了几个别的manager的方法,则这几个别的manager的方法都是required,它们在updateStrategyResult()中会共用一个transaction。结果是这几个方法的SQL 执行只要有一个失败,都会导致其它的方法回滚 (rollback)
public void updateStrategyResult() {
....
saveOrderInfo(orderInfo, remark);
insertOFCSourcingOrderTask(orderQuery);
updateTaskOrder(task, grabObject);
insertWMSDistributionOrderTask(task);
insertOperateLog(orderInfo.getOrderCode(), remark);
lockSkuStock(grabObject);
}
Spring中 PROPAGATION_REQUIRED 解释的更多相关文章
- Spring中 PROPAGATION_REQUIRED 解释 事物是在一个方法里调用其他的方法,一起成功或者一起失败,是方法之间的关系,而不是某一个方法内部的问题。而且要以抛异常的方式来表明方法的失败,以此来导致事物起作用,大家全失败。
事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播: 事务传播行为类型 事务传播 ...
- Spring中IOC和AOP的详细解释
我们是在使用Spring框架的过程中,其实就是为了使用IOC,依赖注入,和AOP,面向切面编程,这两个是Spring的灵魂. 主要用到的设计模式有工厂模式和代理模式. IOC就是典型的工厂模式,通过s ...
- Spring中IOC和AOP的详细解释(转)
原文链接:Spring中IOC和AOP的详细解释 我们是在使用Spring框架的过程中,其实就是为了使用IOC,依赖注入,和AOP,面向切面编程,这两个是Spring的灵魂. 主要用到的设计模式有工厂 ...
- SSM-Spring-16:Spring中一些名词解释
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- JoinPoint(连接点):所谓连接点是指那些被拦截到的点.在spring中,这些点指的是方法,因为spri ...
- 用通俗的语言解释 Spring 中的 DI 、IOC 和AOP概念
DI 所谓依赖,从程序的角度看,就是比如A要调用B的方法,那么A就依赖于B,反正A要用到B,则A依赖于B.所谓倒置,你必须理解如果不倒置,会怎么着,因为A必须要有B,才可以调用B,如果不倒置,意思就是 ...
- Spring学习笔记——Spring中lazy-init与abstract具体解释
Spring的懒载入的作用是为了避免无谓的性能开销,就是当真正须要数据的时候才去运行数据的载入操作.不只在Spring中.我们在实际的编码过程中也应该借鉴这种思想,来提高我们程序的效率. 首先我们看一 ...
- Spring中与Spring相关的注解
# 一.Spring的常用组件类注解 ## @Component 被该注解所修饰的类是一个普通的spring bean类,该注解可以替代@Controller.@Service.@Reposi ...
- Spring事务详细解释
前言 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为.事务传播行为是Spring框架独有的事务增强特性,他不属于的事务实际提供方数据库行为.这是Spring ...
- Spring中的一些面试题
谈谈你对spring IOC和DI的理解,它们有什么区别? IoC [Inverse of Control] 控制反转的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...
随机推荐
- JBoss类隔离
http://tiger888.iteye.com/blog/572875这几天,项目组在部署JBOSS时遇到不少问题,都是由于JBOSS的类装载问题引起,特发表一篇BLOG详细说一下JBOSS的类隔 ...
- linux c++ 文件获取md5
当前在linux系统下,shell命令可以获取md5值,如下: 如果进行c++编程,在代码里执行shell命令可以获得,但是很不雅观,特别是了解了system或者popen函数的机制之后.现在介绍使用 ...
- js+CSS 实现可以编辑的下拉列表框
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...
- navigate是Router类的一个方法,主要用来跳转路由。
navigate是Router类的一个方法,主要用来跳转路由. 1 2 3 4 5 6 7 8 9 interface NavigationExtras { relativeTo : Activat ...
- memcache stats命令详解
参数不算多,我们来启动一个Memcache的服务器端: /usr/local/bin/memcached -d-m 10 -u root-l 192.168.0.200-p 12000-c 256- ...
- Atitit.request http乱码的设计防止 检测与解决最近实践p825 attilax总结.doc
Atitit.request http乱码的设计防止 检测与解决最近实践p825 attilax总结.doc 1 浏览器判断一个页面的编码有俩个途径, 一种是通过HTTP响应头, 一个是通过meta: ...
- C++ STL源代码学习(list篇)
///STL list为双向循环链表 struct _List_node_base { _List_node_base* _M_next; _List_node_base* _M_prev; }; t ...
- 使用ZBar来读取条形码和二维码的方法
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.使用ZBar项目.下载地址是: http://zbar.sourceforge.net/iphone/index.html 2.新建一个项目. ...
- POSTGRESQL 9.1 FATAL: password authentication failed for user "postgres"
1.配置postgreql 可以远程访问: sudo vim /etc/postgresql/9.1/main/postgresql.conf root@ubuntuserver:~# sudo vi ...
- eclispe luna 安装subversive和svn connector插件
1. subversive安装 下载地址: http://www.eclipse.org/subversive/latest-releases.php 或者在eclipse luna的marketpl ...