spring 事务 @Transactional注解参数 tx:annotation-driven
来源:互联网 发布:nginx 子域名映射 编辑:程序博客网 时间:2024/05/21 14:59
首先修改applicationContext.xml如下:
实现类代码:
在配置文件中,默认情况下,<tx:annotation-driven>会自动使用名称为transactionManager的事务管理器。
所以,如果定义的事务管理器名称为transactionManager,那么就可以直接使用<tx:annotation-driven/>。如下:
- mode:指定Spring事务管理框架创建通知bean的方式。可用的值有proxy和aspectj。前者是默认值,表示通知对象是个JDK代理;后者表示Spring AOP会使用AspectJ创建代理
- proxy-target-class:如果为true,Spring将创建子类来代理业务类;如果为false,则使用基于接口的代理。(如果使用子类代理,需要在类路径中添加CGLib.jar类库)
- order:如果业务类除事务切面外,还需要织入其他的切面,通过该属性可以控制事务切面在目标连接点的织入顺序。
- transaction-manager:指定到现有的PlatformTransaction Manager bean的引用,通知会使用该引用
@Transactional注解可以标注在类和方法上,也可以标注在定义的接口和接口方法上。
如果我们在接口上标注@Transactional注解,会留下这样的隐患:因为注解不能被继承,所以业务接口中标注的@Transactional注解不会被业务实现类继承。所以可能会出现不启动事务的情况。所以,Spring建议我们将@Transaction注解在实现类上。
在方法上的@Transactional注解会覆盖掉类上的@Transactional。
使用不同的事务管理器
如果我们要程序中使用多个事务管理器(主要是针对多数据源的情况),可以通过以下的方式实现:
Service代码:
applicationContext.xml配置如下:
经过以上的代码,每个事务都会绑定各自的独立的数据源,进行各自的事务管理。我们可以优化下以上代码,可以自定义一个绑定到特定事务管理器的注解,然后直接使用这个自定义的注解进行标识:
在Service代码中使用:
阅读全文
0 0
- spring 事务 @Transactional注解参数 tx:annotation-driven
- spring 事务 @Transactional注解参数 tx:annotation-driven
- spring 事务 @Transactional注解参数 tx:annotation-driven
- 关于Spring事务<tx:annotation-driven/>的理解(Controller可以使用@Transactional)
- 关于Spring事务<tx:annotation-driven/>的理解(Controller可以使用@Transactional)
- 关于Spring事务<tx:annotation-driven/>的理解(Controller可以使用@Transactional)
- 关于Spring事务<tx:annotation-driven/>的理解(Controller可以使用@Transactional)
- 关于Spring事务<tx:annotation-driven/>的理解。
- 关于Spring事务<tx:annotation-driven/>的理解
- spring中的<tx:annotation-driven>
- spring配置事务 元素 "tx:annotation-driven" 的前缀 "tx" 未绑定
- <tx :annotation-driven> <mvc: annotation-driven >注解理解
- spring 事务 @Transactional注解参数详解
- spring 事务注解@Transactional
- spring 事务注解@Transactional
- spring 事务注解@Transactional
- Spring注解事务@Transactional
- Spring 注解@Transactional 事务
- hadoop收集
- Spring拦截器进行登录拦截
- EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:bootstrap弹窗功能的实现
- Java实现链表反转
- 内存泄漏相关问题
- spring 事务 @Transactional注解参数 tx:annotation-driven
- PHPstorm使用git上传代码
- 写给大数据开发初学者的话
- Windows 10, 1703连接VPN后无法上网
- Qt文件操作
- js之当页面加载$(document).ready(function(){})和window.onload=function(){}的区别
- 谈谈主席树的那些事儿
- bzoj 2761 不重复数字
- 石子合并