From cbaf76a56baa0672b652a277ad8459d17592c29a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=BB=98=E5=BA=86=E5=90=89?= <51312040@qq.com>
Date: Tue, 5 Jan 2021 09:01:21 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dseata=E4=BA=8B=E5=8A=A1?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
uboot-core/pom.xml | 5 ++++
.../ebtp/core/config/FeignSeataConfig.java | 26 +++++++++++++++++++
2 files changed, 31 insertions(+)
create mode 100644 uboot-core/src/main/java/com/chinaunicom/mall/ebtp/core/config/FeignSeataConfig.java
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);
+ }
+ }
+ }
+}