Spring mvc注解方式使用事务回滚
项目名:1ma1ma
jdbc.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
p:maxActive="${jdbc.pool-size}"
p:minEvictableIdleTimeMillis="600000" p:timeBetweenEvictionRunsMillis="900000"
p:removeAbandoned="true" p:logAbandoned="true" p:removeAbandonedTimeout="120"
p:maxWait="5000"
/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="com.yaoma.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
servlet-context.xml
<context:component-scan base-package="com.yaoma.*" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
@Transactional
public int delete(String IMGroupID, String userid) throws Exception {
//依照IMGroupID和userid更新相应的Groups表内容
int is_return = Groups_Dao.IsDeleted_Groups(IMGroupID, userid, 0);
if (is_return == 0) {
throw new RuntimeException("is_return is 0;");
}
//去环信上删除相应的数据
String hx_return = HX_Service.delete_group(IMGroupID);
if (hx_return == null) {
throw new RuntimeException("hx_return is null");
}
return Integer.parseInt(hx_return);
}
@Transactional注解标签
由于在执行中,所以使用RuntimeException进行异常抛出,类中不能使用try捕捉异常,直接throws Exception抛出异常
如执行时使用Exception抛出异常,则回滚无效
Spring mvc注解方式使用事务回滚的更多相关文章
- Spring异常抛出触发事务回滚
Spring.EJB的声明式事务默认情况下都是在抛出unchecked exception后才会触发事务的回滚 /** * 如果在spring事务配置中不为切入点(如这里的切入点可以定义成test*) ...
- (转)spring异常抛出触发事务回滚策略
背景:在面试时候问到事务方法在调用过程中出现异常,是否会传递的问题,平时接触的比较少,有些懵逼. spring异常抛出触发事务回滚策略 Spring.EJB的声明式事务默认情况下都是在抛出unchec ...
- Spring 使用注解方式进行事务管理
转载:http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html 使用步骤: 步骤一.在spring配置文件中引入<tx:&g ...
- spring boot 使用 mybatis 开启事务回滚 的总结
1.前言 以前没有使用mybatis,可以关闭自动提交,然后做sql操作,对操作进行catch捕获异常, 如果没有异常则commit 提交 ,有异常则 rollback 回滚,新增的数据则删除 ,修改 ...
- junit4测试 Spring MVC注解方式
本人使用的为junit4进行测试 spring-servlet.xml中使用的为注解扫描的方式 <?xml version="1.0" encoding="UTF- ...
- [转]spring mvc注解方式实现向导式跳转页面
由于项目需要用到向导式的跳转页面效果,本项目又是用spring mvc实现的,刚开始想到用spring 的webflow,不过webflow太过笨重,对于我们不是很复杂的跳转来说好像有种“杀鸡焉用牛刀 ...
- 事务之二:spring事务(事务管理方式,事务5隔离级别,7个事务传播行为,spring事务回滚条件)
事物管理对于企业应用来说是至关重要的,好使出现异常情况,它也可以保证数据的一致性. spring支持编程式事务管理和声明式事务管理两种方式. 编程式事务管理使用TransactionTemplate或 ...
- Spring事务回滚和异常类
1.异常的一些基本知识 异常的架构 异常的继承结构:Throwable为基类,Error和Exception继承Throwable.Error和RuntimeException及其子类成为未检查异常( ...
- 浅谈Spring中的事务回滚
使用Spring管理事务过程中,碰到过一些坑,因此也稍微总结一下,方便后续查阅. 1.代码中事务控制的3种方式 编程式事务:就是直接在代码里手动开启事务,手动提交,手动回滚.优点就是可以灵活控 ...
随机推荐
- Turn any Linux computer into SOCKS5 proxy in one command
src: http://www.catonmat.net/blog/linux-socks5-proxy/ I thought I'd do a shorter article on catonmat ...
- pytest文档6-fixture之yield实现teardown
前言 上一篇讲到fixture通过scope参数控制setup级别,既然有setup作为用例之前前的操作,用例执行完之后那肯定也有teardown操作. 这里用到fixture的teardown操作并 ...
- matlab 图像常用函数
Canny function [ canny ] = canny( rgb ) temp=rgb2gray(rgb); canny=edge(temp,'canny'); end 灰度 temp=rg ...
- 重新总结flex布局(flex,flex-direction,justify-content,align-items,flex-wrap,align-self)
1.flex,主要就是按比例分配.(例如:两个div的flex:1,就大小相等) .box1{ flex:1; background-color: red; } .box2{ flex:1; back ...
- Computer Generated Angular Fisheye Projections [转]
Computer GeneratedAngular Fisheye Projections Written by Paul Bourke May 2001 There are two main ide ...
- Unity3D 浅谈被忽略的Quality [转]
开始分享之前,我先墨迹几句... 最近在工作上,在交流群中,都会遇到一些问题.比如: 为什么打包Android Apk以后,图片变模糊了? 为什么移动端的阴影和电脑端不一样? 我的电脑明明配置很好,为 ...
- javascript模拟post提交
通过js模拟post提交1:请求需要的参数过长,超过get允许的最大长度2:想要隐藏地址栏的参数 //新创建一个form表单document.write('<form name=myForm&g ...
- List、Set、Map、数组之间各种转换
刚学Java不久的时候,接到一个电面,然后问了一些java的知识,比如说Java的编码,Unicode等,但是最让我蛋疼的是怎么吗map转为set,那个时候对集合用的很少,对集合不是特别了解,map还 ...
- 【Linux】shell中svn报错:svn: Can't convert string from 'UTF-8' to native encoding:xxx
解决办法: shell中svn命令之前添加: #!/bin/bash export LC_ALL=en_US.UTF- export LANG=en_US.UTF- export LANGUAGE=e ...
- MapReduce开发技巧
数据类型的选择 自定义数据类型 参考:Hadoop提交作业自定义排序和分组 MapWritable/SortedMapWritable Hadoop中可传输的Map集合,和Java中的Map用法差不多 ...