Spring事务<tx:annotation-driven/>的理解
在使用Spring的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx、mvc 等也能很直白的理解出来分别的作用。
<tx:annotation-driven/> 就是支持事务注解的(@Transactional) 。
<mvc:annotation-driven> 就是支持mvc注解(Controller中可以使用MVC的各种注解)。
<tx:annotation-driven/> 会有一个属性来指定使用哪个事务管理器,如:
<tx:annotation-driven transaction-manager="txManager" />//txManager就是指定的事务管理器
这样逐层引用下去,所以我们使用@Transactionl 注解可以控制事务就通俗易懂了。
另外要提一下的就是 Spring 是使用 aop 通过 asm 操作Java字节码的方式来实现对方法的前后事务管理的。
那我们是否就可以在程序中所有被spring管理的类上都可以使用@Transactional注解了呢,在Service上可以使用@Transactional 注解这个是肯定的了,那总有些人也想弄明白能否在Controller 使用?答案显然是“不一定”的(与时间配置有关),下面做下解释:
在 spring-framework-reference.pdf 文档上有这样一段话:
<tx:annotation-driven/> only looks for @Transactional on beans in the same application context
it is defined in. This means that, if you put <tx:annotation-driven/> in a WebApplicationContext
for a DispatcherServlet, it only checks for @Transactional beans in your controllers,
and not your services.
翻译:<tx:annoation-driven/>只会查找和它在相同的应用上下文件中定义的bean上面的@Transactional注解,如果你把它放在Dispatcher的应用上下文中,它只检查控制器(Controller)上的@Transactional注解,而不是你services上的@Transactional注解。
所以,可以确定的是我们是可以在Controller上使用事务注解的,但是我们不推荐这样做,这里只是为了说明spring对<tx:annotation-driven/>的使用。
参考网址https://my.oschina.net/wuminghai/blog/760033
Spring事务<tx:annotation-driven/>的理解的更多相关文章
- 关于Spring事务<tx:annotation-driven/>的理解(Controller可以使用@Transactional)
在使用SpringMvc的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用.<tx: ...
- Spring事务<tx:annotation-driven/>的理解(Controller使用@Transactional)
在使用Spring的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用. <tx:an ...
- [转]Spring事务<tx:annotation-driven/>
在使用SpringMVC的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用.<tx: ...
- spring事务的传播性的理解
来自至顶网的文章 http://developer.zdnet.com.cn/2007/0521/402066.shtml
- 简述Spring事务有几种管理方法,写出一种配置方式
Spring事务有两种方式: 1.编程式事务:(代码中嵌入) 2.声明式事务:(注解,XML) 注解方式配置事务的方式如下: 首先,需要在applicationContext.xml中添加启动配置,代 ...
- spring事务之事务传播机制和隔离级别
Spring事务传播行为 运用Spring事务,必须要深入理解它的传播机制,否则会遇到各种意想不到的坑,Spring定义了七种传播行为. public interface TransactionDef ...
- 【spring】 <tx:annotation-driven /> 的理解 【转载的】
在使用SpringMvc的时候,配置文件中我们经常看到 annotation-driven 这样的注解,其含义就是支持注解,一般根据前缀 tx.mvc 等也能很直白的理解出来分别的作用.<tx: ...
- spring事务管理器的源码和理解
原文出处: xieyu_zy 以前说了大多的原理,今天来说下spring的事务管理器的实现过程,顺带源码干货带上. 其实这个文章唯一的就是带着看看代码,但是前提你要懂得动态代理以及字节码增强方面的知识 ...
- Spring配置--tx事务配置方式
前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识.通过这次的学习发觉Spring的事务配置只要把思路理清,还是比较好掌握的. ...
随机推荐
- 经典论文翻译导读之《Google File System》(转)
[译者预读] GFS这三个字母无需过多修饰,<Google File System>的论文也早有译版.但是这不妨碍我们加点批注.重温经典,并结合上篇Haystack的文章,将GFS.TFS ...
- [linux]如何更新Ubuntu的数据源
为何要更新数据源?国外的数据源,除了速度慢这个次要因素,更可怕的是有些链接根本不通,导致用户既没有下载东西,也没有看到实质性提示:潜在的危险就是编译错误不能定位,严重时甚至重装系统.本文介绍几个国内有 ...
- 命名空间与use
以下是自己读PHP手册命名空间这一节的一些笔记,还有自己上机做命名空间测试的一些整理,原创博客,有错欢迎指正: 1.命名空间声明必须是第一条语句,若没有声明命名空间的脚本,则被认为是全局空间的脚本.若 ...
- 实现一个简单的shell
使用已学习的各种C函数实现一个简单的交互式Shell,要求:1.给出提示符,让用户输入一行命令,识别程序名和参数并调用适当的exec函数执行程序,待执行完成后再次给出提示符.2.该程序可识别和处理以下 ...
- C#中让WebBrowser运行Javascript脚本
C#中可以让Webbrowser运行Javascript脚本来实现各种自动化操作,比如点击网页上的按钮,输入用户名密码等等.代码也很简单: >>>>>>>&g ...
- Android文档 学习目录
Building Your First App After you've installed the Android SDK, start with this class to learn the b ...
- tf.identity 个人理解
tf.identity is useful when you want to explicitly transport tensor between devices (like, from GPU t ...
- php导出excel不知道列数 php26进制函数
function num2Letter($num) { $num = intval($num); if ($num <= 0) return false; $letterArr = array( ...
- 开启Centos系统的SSH服务
1.登录Centos6.4系统. ◆示例:使用root用户登录. 注:若为非root用户登录,输入执行某些命权限不够时需加sudo. 查看SSH是否安装. 2.◆输入命令:rpm -qa | grep ...
- destructuring assignment
[destructuring assignment] The destructuring assignment syntax is a JavaScript expression that makes ...