fegin threadlocal
时间: 2023-10-19 15:30:48 浏览: 122
在使用Feign调用时,如果开启了Hystrix,那么无法直接获取ThreadLocal中的数据。解决这个问题的方法有两种。一种是将hystrix的enabled设为false,即feign.hystrix.enabled=false,这样就可以继续使用ThreadLocal。另一种方法是将ThreadLocal换成InheritableThreadLocal,也就是使用InheritableThreadLocal来保存数据。InheritableThreadLocal是ThreadLocal的子类,可以解决父线程和子线程的数据传输问题。 这样,当开启了Hystrix时,依然可以在子线程中获取到父线程中设置的数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [SpringCloud微服务间参数的传递( threadLocal+Feign的RequestInterceptor方式)](https://blog.csdn.net/h_sn9999/article/details/103152196)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Feign调用开启Hystrix时无法获取ThreadLocal](https://blog.csdn.net/weixin_48240945/article/details/120370002)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文