diff --git a/uboot-core/pom.xml b/uboot-core/pom.xml index 0009a35..fc4766a 100644 --- a/uboot-core/pom.xml +++ b/uboot-core/pom.xml @@ -49,6 +49,11 @@ mall-ebtp-cloud-redis-starter + + com.chinaunicom.ebtp + mall-ebtp-cloud-seata-starter + + com.baomidou mybatis-plus-generator diff --git a/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java b/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java new file mode 100644 index 0000000..1b05ef0 --- /dev/null +++ b/uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java @@ -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); + } + } + } +}