gpt4 book ai didi

java - 为什么 Spring 在 TransactionSynchronization 接口(interface)中没有回滚方法?

转载 作者:行者123 更新时间:2023-11-29 09:32:05 29 4
gpt4 key购买 nike

在 Spring TransactionSynchronization 接口(interface)中它有方法(按执行顺序):

- beforeCommit
- beforeCompletion
- afterCommit: Can perform further operations right after the main transaction has successfully committed.
- afterCompletion

为什么 Spring 没有回滚方法,例如 beforeRollback 或 afterRollback 但它只有提交(beforeCommit 和 afterCommit)?请问这个有必要吗?任何人都可以给我一些建议或解释吗?

如果我想在主事务成功回滚后继续执行进一步的操作,例如通知消息或电子邮件,在这种情况下我应该怎么做?

最佳答案

                    @Override
public void afterCompletion(int status) {
if (status == TransactionSynchronization.STATUS_ROLLED_BACK) {
logger.trace("Rolled back...");
}
}

关于java - 为什么 Spring 在 TransactionSynchronization 接口(interface)中没有回滚方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28757007/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com