try catch后spring 事物不显式提交
来源:互联网 发布:excel怎么统计重复数据 编辑:程序博客网 时间:2024/06/10 15:14
spring管理的事物,例如声明式事物或者是注解式事物默认是在抛出运行异常时,会被spring catch到然后回滚,如果你在需要事物管理的方法里就已经try,catch了。哪么spring就捕获不到这个异常,也就不会回滚了。
例如:
public void doSome(){ try{ update ..... delete ..... }catch(Exception e){ }}
spring aop 管理上面方法的事物:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" <property name="driverClassName" value="${jdbc.driverClassName}"/ <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="initialSize" value="${jdbc.initialSize}"/> <property name="maxActive" value="${jdbc.maxActive}"/> <property name="maxIdle" value="${jdbc.maxIdle}"/> <property name="minIdle" value="${jdbc.minIdle}"/> <property name="maxWait" value="${jdbc.maxWait}"/> <property name="socketTimeout" value="60000"/> </bean><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="do*" propagation="REQUIRED" rollback-for="java.lang.Exception" /> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(*..*.*(..))" advice-ref="txAdvice" /></aop:config>
如果上述delete方法出错,update是不会回滚的,依然会提交。
因为你已经在业务层就try catch了,spring抓不到你的excetion也就不会回滚。
如果你依然要加try catch而且还要回滚,可以在catch中加入 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
阅读全文
0 0
- try catch后spring 事物不显式提交
- spring中事物回滚与异常try catch相关
- try catch异常后,spring的异常是否还有效
- 使用Spring管理,在try-catch后不会滚解决
- Spring手动提交事物
- SQL2005之try、catch,事物,存储过程(范例)
- sql serverl 事物回滚三(try...catch事务回滚)
- try{}catch(Exception e){}与spring事务
- Spring.Net使用事务,try catch不回滚
- spring事物的提交与回滚
- try catch
- try{} catch{}
- try catch
- try...catch
- try{} catch(...){}
- try catch
- try-catch
- try catch
- 剑指offer——数组中只出现一次的数
- Joda DateTime API
- forward 和redirect的区别
- Spring配置定时任务,时间放到配置文件
- java关键字final
- try catch后spring 事物不显式提交
- telnet 使用
- MySQL日期时间函数大全
- MySQL 入门教程
- Libcurl安装及编译
- ImageSpan 图文混排居中
- MYSQL-SHOW VARIABLES 详解
- Sql Server中将日期转换为yyyy-mm格式
- mysql数据库设计