From 3134a608054233ddd6ef5f6452050050b738cead Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 14 Feb 2022 11:03:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E7=BA=BF=E7=A8=8B=E9=87=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AD=90=E7=BA=BF=E7=A8=8B=E8=B0=83=E7=94=A8feign?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E9=80=9A=E8=BF=87header=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=A4=B4=E5=B8=A6token=E4=BF=A1=E6=81=AF=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/feign/FeignConfig.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignConfig.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignConfig.java index ec7806a620..5bf8a82715 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignConfig.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/FeignConfig.java @@ -10,9 +10,14 @@ package com.epmet.commons.tools.feign; import feign.Logger; import feign.RequestInterceptor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.RequestContextFilter; +import org.springframework.web.servlet.DispatcherServlet; + +import javax.annotation.PostConstruct; /** @@ -24,6 +29,10 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class FeignConfig { + @Autowired + RequestContextFilter requestContextFilter; + @Autowired + DispatcherServlet dispatcherServlet; @Bean @ConditionalOnMissingBean @@ -37,5 +46,10 @@ public class FeignConfig { return Logger.Level.BASIC;//控制台会输出debug日志 } - + @PostConstruct + public void init() { + // 设置线程继承属性为true,便于子线程获取到父线程的request,两个都设置为了保险。 + requestContextFilter.setThreadContextInheritable(true); + dispatcherServlet.setThreadContextInheritable(true); + } }