Spring 手动提交事务
在使用Spring声明式事务时,不需要手动的开启事务和关闭事务,但是对于一些场景则需要开发人员手动的提交事务,比如说一个操作中需要处理大量的数据库更改,可以将大量的数据库更改分批的提交,又比如一次事务中一类的操作的失败并不需要对其他类操作进行事务回滚,就可以将此类的事务先进行提交,这样就需要手动的获取Spring管理的Transaction来提交事务。
1、applicationContext.xml配置
<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="*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="find*" read-only="true" propagation="SUPPORTS" />
<tx:method name="get*" read-only="true" propagation="SUPPORTS" />
<tx:method name="select*" read-only="true" propagation="SUPPORTS" />
<tx:method name="list*" read-only="true" propagation="SUPPORTS" />
<tx:method name="load*" read-only="true" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="servicePointCut" expression="execution(* com.xxx.xxx.service..*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointCut" />
</aop:config>
2、手动提交事务
@Resource(name="transactionManager")
private DataSourceTransactionManager transactionManager; DefaultTransactionDefinition transDefinition = new DefaultTransactionDefinition();
//开启新事物
transDefinition.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus transStatus = transactionManager.getTransaction(transDefinition);
try {
//TODO
transactionManager.commit(transStatus);
} catch (Exception e) {
transactionManager.rollback(transStatus);
}
Spring 手动提交事务的更多相关文章
- Spring 手动 提交事务
1.配置文件 applicationContext.xml: <bean id="txManager"class="org.springframework.jdbc ...
- Spring手动提交事务
// name的值根据spring配置文件的事物管理器的id而定 @Resource(name="transactionManager") private DataSourceTr ...
- Java中手动提交事务
项目中遇到一个问题,就是在程序的执行过程中需要不断地更新某个信息,但是在springmvc中好像是默认不可以的,那么就需要手动提交 // 从spring容器对象中获取DataSourceTransac ...
- mysql中,手动提交事务
1: 在mysql中,手动提交事务的案例:CREATE PROCEDURE tfer_funds (from_account int, to_account int, tfer_amoun ...
- (后端)Spring手动回滚事务
百度上查资料获得的 throw new RuntimeException(); 或者 TransactionAspectSupport.currentTransactionStatus().setR ...
- spring手动配置
本文总结自:https://www.cnblogs.com/V1haoge/p/7183408.html SpringBoot中免除了大部分配置,但是对于一些特定的情况,还是需要我们进行手动配置的. ...
- 使用spring手动获取Bean的时候,不能强转回它自己。
这个问题好像有点长,描述一下: 就是通过类名的方式获取Bean后,得到一个Object对象,但是这个Object不能再强转回Bean了.抛出的异常时类型转换异常. java.lang.ClassCa ...
- springboot 开启事务以及手动提交事务
添加依赖,sprongboot 会默认开启事务管理 org.springframework.boot spring-boot-starter-jdbc 在需要的服务类里添加注解 @Autowired ...
- 【Oracle】使用bbed手动提交事务
有时候数据库挂掉,起库会出现ORA-00704错误,而导致ORA-00704错误的根本原因是訪问OBJ$的时候.ORACLE须要回滚段中的数据,而訪问回滚段的时候须要的undo数据已经被覆盖,此时我们 ...
随机推荐
- VS2013的安装与C#进行简单单元测试(英文版教程)
这次安装这个软件可是花了我不少时间,其中遇到的问题不言而喻,下面讲解一下我完成这次作业以及分享一些个人体会吧! 第一步:提供下载地址(https://www.visualstudio.com/down ...
- Centos7 Zookeeper 集群安装
1:安装java 环境 -openjdk* 2:zookeeper 安装 (官网 http://www.apache.org/dyn/closer.cgi/zookeeper/) 2.1 目录创建 自 ...
- 安装/卸载 修改Config
参考地址:https://docs.microsoft.com/zh-cn/nuget/create-packages/source-and-config-file-transformations
- 关于Jquery使用中遇到典型问题集锦
①$.post("url",{search:1},function(){},"json")请求数据成功就是不执行回调函数? 答:最大可能导致原因为 数据格式不正 ...
- Android 开发工具下载中文网站
Android官方网站(develop.android.com)因为被墙而无法访问.这时可以访问中文网址: http://wear.techbrood.com/ SDK Manager 代理及安装文件 ...
- vue-cli配置axios
1. npm install axios --save 2. npm install @type/axios --save-dev(使用ts编写的需要此声明文件,升级的axios好像不需要了,已经自带 ...
- jion()说明
转自:http://www.cnblogs.com/skywang12345/p/3479275.html jion(),只有当子线程执行完了,主线程才会执行 1. join()介绍 join() 定 ...
- Augmenting DOM Storage with IE's userData behavior
http://www.javascriptkit.com/javatutors/domstorage2.shtml Augmenting DOM Storage with IE's userData ...
- APP 测试 与 WEB 测试的本质区别
单纯从功能测试的层面上来讲的话,APP 测试.web 测试 在流程和功能测试上是没有区别的 根据两者载体不一样,则区别如下: 1.系统结构方面 web项目,b/s架构,基于浏览器的:web测试只要更新 ...
- BZOJ5099 POI2018Pionek
假设确定了最终所得向量的方向,则应该选择所有在该方向上投影为正的向量.按极角序排序后这显然是一段连续区间.最终向量方向很难枚举,但对于某个向量,在其上投影为正的向量与其夹角范围是(-π/2,π/2), ...