0
点赞
收藏
分享

微信扫一扫

seata 分布式事务没有传递xid导致事务失效解决方案

落花时节又逢君to 2022-04-23 阅读 85
java

seata 分布式事务没有传递xid导致事务失效解决方案

当spring cloud 设置全局开启分布式事务,在调用分支事务没有传递xid,原因是feign或者http调用时候 header 没有put xid,可以在SeataHandlerInterceptor.preHandle 方法验证,如果xid 为null则代表 调用分支事务进行http调用或者feign调用没有put 事务xid。

@Configuration
public class FeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        String xid = RootContext.getXID();
        if (StringUtils.isNotEmpty(xid)) {
            requestTemplate.header(RootContext.KEY_XID, xid);
        }
    }
}

链接:详细见link

举报

相关推荐

0 条评论