From 766c48bdbf379fa914aa7ce6326104699cf08457 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Sat, 20 Feb 2021 20:59:13 +0800 Subject: [PATCH] =?UTF-8?q?feign=20=E5=8A=A8=E6=80=81=E5=88=9B=E5=BB=BAcli?= =?UTF-8?q?ent=EF=BC=8C=E6=8B=A6=E6=88=AA=E5=99=A8=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=20#2275?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloud/feign/impl/JeecgFeignService.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/impl/JeecgFeignService.java b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/impl/JeecgFeignService.java index a9a0d6ad..19678a0c 100644 --- a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/impl/JeecgFeignService.java +++ b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/src/main/java/org/jeecg/starter/cloud/feign/impl/JeecgFeignService.java @@ -35,25 +35,26 @@ public class JeecgFeignService implements IJeecgFeignService { .encoder(encoder) .decoder(decoder) .contract(contract); + + builder.requestInterceptor(requestTemplate -> { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (null != attributes) { + HttpServletRequest request = attributes.getRequest(); + log.info("Feign request: {}", request.getRequestURI()); + // 将token信息放入header中 + String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); + if(token==null){ + token = request.getParameter("token"); + } + log.info("Feign request token: {}", token); + requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); + } + }); } @Override public T newInstance(Class clientClass, String serviceName) { - builder.requestInterceptor(requestTemplate -> { - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (null != attributes) { - HttpServletRequest request = attributes.getRequest(); - log.info("Feign request: {}", request.getRequestURI()); - // 将token信息放入header中 - String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); - if(token==null){ - token = request.getParameter("token"); - } - log.info("Feign request token: {}", token); - requestTemplate.header(CommonConstant.X_ACCESS_TOKEN, token); - } - }); return builder.target(clientClass, String.format("http://%s/", serviceName)); } } \ No newline at end of file