Fegin调用使用了Fallback降级或抛出的异常被全局处理
解决:
1.通过 GlobalTransactionContext.reload(RootContext.getXID()).rollback() 进行手动回滚
==============服务A @Service public class ServiceAImpl implements IServiceA { private static final Logger log = LoggerFactory.getLogger(ServiceAImpl.class); @Autowired private IServiceB serviceB; @Autowired private IServiceC serviceC; @Override @GlobalTransactional @Transactional public Boolean doA() { Integer bStatus = serviceB.doB(); if(bStatus == 0){//在Mybatis中,返回值为0证明插入失败 //手动回滚 GlobalTransactionContext.reload(RootContext.getXID()).rollback(); return false; } Integer cStatus = serviceC.doC(); if(cStatus == 0){//在Mybatis中,返回值为0证明插入失败 //手动回滚 GlobalTransactionContext.reload(RootContext.getXID()).rollback(); return false; } //...... } } ===============服务B @Service public class ServiceBImpl implements IServiceB { private static final Logger log = LoggerFactory.getLogger(ServiceBImpl.class); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public Boolean doB() { //...... Integer insertStatus = serviceBDAO.insert(); return insertStatus; } } ===============服务C @Service public class ServiceCImpl implements IServiceC { private static final Logger log = LoggerFactory.getLogger(ServiceCImpl.class); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public Boolean doC() { //...... Integer insertStatus = serviceCDAO.insert(); return insertStatus; } }
2.直接在FallbackFactory实现类直接将异常抛出或者不实现fallbackFactory
标签:return,seata,insertStatus,private,class,生效,Integer,public,分布式 From: https://www.cnblogs.com/Ai-Hen-Jiao-zhi/p/17916743.html