@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.
*/
@Override
public boolean rollbackOn(Throwable ex) {
return (ex instanceof RuntimeException || ex instanceof Error);
}
}
即RuntimeException和Error
本文探讨了Spring框架中默认的事务回滚机制。当使用DefaultTransactionAttribute时,Spring会在遇到RuntimeException或Error时自动回滚事务。这与EJB的行为一致,并且也符合TransactionTemplate的默认行为。
2843

被折叠的 条评论
为什么被折叠?



