默认事务传播级别:REQUIRED
ClassA:REQUIRED
if (TransactionSynchronizationManager.isActualTransactionActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@SneakyThrows
@Override
public void afterCommit() {
handle(xxxx,xxxx,xxx);
}
});
}
ClassB:REQUIRED
handle中也存在,事务提交后执行
if (TransactionSynchronizationManager.isActualTransactionActive()) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@SneakyThrows
@Override
public void afterCommit() {
handleB(xxxx,xxxx,xxx);
}
});
}
问题:handleB在事务提交后,不会被唤起
猜测:REQUIRED以加入事务方式运行,子方法里的afterCommit逻辑没保留?
暂时处理:ClassB传播级别调整为REQUIRED_NEW或NESTED可以暂时解决(两种根据事务回滚情况,酌情选择),(ClassB用的地方多的话,考虑重载方法)
具体原因后续扒源码分析下