当前位置:网站首页>Solution to the problem of token loss when microservice feign is called
Solution to the problem of token loss when microservice feign is called
2022-07-26 07:34:00 【zero _ s】
feign The principle of microservice invocation is to send a http request , At this time, the original token, So when calling the interface of another service ,token Will lose , It needs to be handled in the code , hold token Carry the past ;
commonly http Requested token In the request header ;
Solution :
(1) New interceptors
Inside the interceptor , obtain token, Then join in templete Inside ;
/**
* feign Call missing token Solution , New interceptors
* @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);
}
}
};
}
Generally, you need to add this code to the interceptors of all involved microservices ; So I will join common Inside the module
边栏推荐
- 2019 ZTE touyue · model compression scheme
- 排序:归并排序和快速排序
- 什么是消息订阅和发布?
- ShardingSphere数据分片
- NFT digital collection system development: how enterprises develop their own digital collection platform
- C # use log4net to record logs (basic chapter)
- VScode无法启动问题解决思路
- Basic knowledge of convolutional neural network
- 微服务feign调用时候,token丢失问题解决方案
- Jmeter性能测试之使用存储响应内容到文件监听器
猜你喜欢

Apache dolphin scheduler 2.x nanny level source code analysis, China Mobile engineers uncover the whole process of service scheduling and start

C # use log4net to record logs (basic chapter)

MySQL之执行计划

正则表达式规则以及常用的正则表达式

Oauth2.0 series blog tutorial summary

现在开发人员都开始做测试了,是不是以后就没有软件测试人员了?

Configure flask

HCIP---MPLS详解和BGP路由过滤

Pycharm common shortcut keys

NFT digital collection system development: what are the best digital marketing strategies for NFT digital collection
随机推荐
ShardingSphere数据分片
从Boosting谈到LamdaMART
Come across the sea to see you
Redis系列之什么是布隆过滤器?
JWT quick start
DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
KDD2022 | 揭秘快手短视频推荐Re-ranking之谜,相关推荐新SOTA
如何保证缓存和数据库的双写一致性?
漂洋过海来看你
Fang Wenshan, Jay Chou's best partner, will officially announce "Hualiu yuancosmos" on July 25
Oauth2.0 series blog tutorial summary
2019中兴捧月·模型压缩方案
Jmeter性能测试之使用存储响应内容到文件监听器
Next item recommendations in short sessions
This section is for Supplement 2
tensorflow2.x中的量化感知训练以及tflite的x86端测评
Summary of API method
keras学习之:获取神经网络中间层的输出结果
Compose text and icon splicing to realize drawableleft or drawableright
The analysis, solution and development of the problem of router dropping frequently