当前位置:网站首页>微服务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模块里面
边栏推荐
- Sort: merge sort and quick sort
- 配置Flask
- “尝鲜”元宇宙,周杰伦最佳拍档方文山将于7月25日官宣《华流元宇宙》
- 0 dynamic programming leetcode1567. Length of the longest subarray with positive product
- Kdd2022 | uncover the mystery of Kwai short video recommendation re ranking, and recommend the new SOTA
- Upgrade ecological proposition: what has Alibaba cloud brought to thousands of businesses?
- C # use log4net to record logs (basic chapter)
- NFT digital collection system development: how enterprises develop their own digital collection platform
- 【uniapp】多种支付方式封装
- Download and install the free version of typora
猜你喜欢

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

KDD2022 | 揭秘快手短视频推荐Re-ranking之谜,相关推荐新SOTA

WCF deployed on IIS

Meta universe infrastructure: analysis of the advantages of Web 3.0 chain33

Learning Efficient Convolutional Networks Through Network Slimming

From boosting to lamdamart

机器学习相关比赛网站

数据库基础

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

Hcip - MPLS Technology
随机推荐
0 dynamic programming leetcode1567. Length of the longest subarray with positive product
Wrong Addition
NFT数字藏品开发:数字藏品与NFT的六大区别
MySQL syntax (2) (pure syntax)
QT: list box, table, tree control
PXE efficient batch network installation
DevExpress.XtraEditors.DataNavigator用法
Model pruning 3: learning structured sparsity in deep neural networks
爬虫->TpImgspider
IDEA快捷键
HOT100 hash
Speech at 2021 global machine learning conference
:app:checkDebugAarMetadata 2 issues were found when checking AAR metadata: 2 issues were found when
PXE高效批量网络装机
Regular expression rules and common regular expressions
依赖和关联的对比和区别
WCF deployed on IIS
Kdd2022 | uncover the mystery of Kwai short video recommendation re ranking, and recommend the new SOTA
6. Combined data type
NLP自然语言处理-机器学习和自然语言处理介绍(三)