@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