@Configuration
public class FeignConfig {
@Bean("requestInterceptor")
public RequestInterceptor requestInterceptor() {
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate requestTemplate) {
//拿到刚进来的这个请求
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
//同步请求头数据,cookie
String cookie = request.getHeader("Cookie");
requestTemplate.header("Cookie", cookie);
}
};
}
}
原文:https://www.cnblogs.com/liuA/p/14348696.html