修复seata事务问题

This commit is contained in:
付庆吉
2021-01-05 09:01:21 +08:00
parent c0fbe9f791
commit cbaf76a56b
2 changed files with 31 additions and 0 deletions

View File

@ -49,6 +49,11 @@
<artifactId>mall-ebtp-cloud-redis-starter</artifactId>
</dependency>
<dependency>
<groupId>com.chinaunicom.ebtp</groupId>
<artifactId>mall-ebtp-cloud-seata-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>

View File

@ -0,0 +1,26 @@
package com.chinaunicom.mall.ebtp.core.config;
import com.chinaunicom.mall.ebtp.common.config.FeignConfig;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@Configuration
public class FeignSeataConfig extends FeignConfig {
@Override
public void apply(RequestTemplate template) {
super.apply(template);
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (null != attributes) {
String xid = RootContext.getXID();
if (StringUtils.isNotEmpty(xid)) {
template.header(RootContext.KEY_XID, xid);
}
}
}
}