当前位置:网站首页>微服务feign调用时候,token丢失问题解决方案
微服务feign调用时候,token丢失问题解决方案
2022-07-26 07:30:00 【zero _s】
feign 微服务调用的原理是发送一个http请求,此时不会携带原来的token,因此在调用另一个服务的接口的时候,token会丢失,需要在代码里面处理,把token携带过去;
一般http请求的token在请求头里面;
解决方案:
(1) 新增拦截器
在拦截器里面,获取token,然后加入到templete里面;
/**
* feign 调用丢失token解决方案,新增拦截器
* @return
*/
@Bean
public RequestInterceptor requestInterceptor(){
return templete -> {
ServletRequestAttributes requestAttributes =
(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(requestAttributes != null){
HttpServletRequest request = requestAttributes.getRequest();
if(request == null){
return ;
}else{
String token = request.getHeader("token");
templete.header("token",token);
}
}
};
}
一般需要将这块代码加入到所有涉及的微服务的拦截器里面;所以会加入到common模块里面
边栏推荐
- OAuth2.0系列博客教程汇总
- NFT数字藏品开发:数字藏品与NFT的六大区别
- WCF 部署在IIS上
- 博途PLC一阶滞后系统传递函数阶跃响应输出仿真(SCL)
- The interface automation test with a monthly salary of 12k+ takes you to get started in 3 minutes
- Idea shortcut key
- OVSDB
- NFT digital collection system development: digital collections give new vitality to brands
- What is bloom filter in redis series?
- 元宇宙基础设施:WEB 3.0 chain33 优势分析
猜你喜欢

排序:归并排序和快速排序

Network Trimming: A Data-Driven Neuron Pruning Approach towards Efficient Deep Architectures论文翻译/笔记

Hcip - MPLS Technology

Hcip--- MPLS detailed explanation and BGP route filtering

Regular expression rules and common regular expressions

NFT数字藏品系统开发:华为发布首款珍藏版数字藏品

深度学习模型部署

配置Flask

Oauth2.0 series blog tutorial summary

总结软件测试岗的那些常见高频面试题
随机推荐
How to expand and repartition the C disk?
ARIMA model for time series analysis and prediction
NLP自然语言处理-机器学习和自然语言处理介绍(三)
C语言关键字extern
WCF deployed on IIS
:app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
[keras entry log (3)] sequential model and functional model in keras
C51 and MDK coexist keil5 installation tutorial
This section is for Supplement 2
[daily question 1] 919. Complete binary tree inserter
DevExpress.XtraEditors.DataNavigator用法
Keras learning part: obtaining the output results of neural network middle layer
6、组合数据类型
HCIP---MPLS详解和BGP路由过滤
Oauth2.0 series blog tutorial summary
NFT digital collection development: digital art collection enabling public welfare platform
NFT数字藏品开发:数字藏品与NFT的六大区别
NFT数字藏品系统开发:NFT数藏 的最佳数字营销策略有哪些
NFT数字藏品系统开发:文学+数字藏品的碰撞
QT: list box, table, tree control