解决方案:在调用方配置Feign的拦截器
?
@Configuration
public class FeignInterceptor {
@Bean
public RequestInterceptor requestInterceptor() {
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate template) {
// 获取Request对象
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
// 获取请求头
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = headerNames.nextElement();
String value = request.getHeader(key);
// 在Feign调用的时候手动的把请求头的信息添加到Feign的请求对象中
template.header(key, value);
}
}
};
}
}
|