Feign远程调用丢失请求头问题
作者:互联网
feign远程调用时会构建一个新的请求模板
解决:
使用feign请求拦截器requestInterceptor给新的请求模板加上请求头
@Configuration public class GuliFeignConfig { @Bean("requestInterceptor") public RequestInterceptor requestInterceptor(){ return new RequestInterceptor() { @Override public void apply(RequestTemplate template) { //1、RequestContextHolder拿到刚进来的请求 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); if (attributes!=null){ HttpServletRequest request = attributes.getRequest(); //老请求 //同步请求头数据,Cookie String cookie = request.getHeader("Cookie"); //给新请求同步了老请求的cookie template.header("Cookie",cookie); } } }; } }
标签:Feign,调用,请求,Cookie,丢失,attributes,cookie,requestInterceptor,public 来源: https://www.cnblogs.com/jiutang001/p/16141038.html