spring事务管理默认回滚异常

来源:互联网 发布:网络监控测试仪 编辑:程序博客网 时间:2024/05/16 06:41

@Transactional(rollbackfor = "xxx.xxx.xException")

可以设置当抛出哪些异常时进行回滚,那么当不设置此属性时,Spring事务管理默认对哪些异常回滚呢?

通过查看Spring的源码,可以找到

package org.springframework.transaction.interceptor;public class DefaultTransactionAttribute extends DefaultTransactionDefinition implements TransactionAttribute {      /** * The default behavior is as with EJB: rollback on unchecked exception. * Additionally attempt to rollback on Error. * <p>This is consistent with TransactionTemplate's default behavior. */@Overridepublic boolean rollbackOn(Throwable ex) {return (ex instanceof RuntimeException || ex instanceof Error);}}

即RuntimeException和Error


原创粉丝点击