public class FeignInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (requestAttributes == null){
return;
}
HttpServletRequest httpServletRequest = requestAttributes.getRequest();
//设置tokenid
requestTemplate.header("tokenId",httpServletRequest.getHeader("tokenId"));
/**
* 网关或者线程池内有时候没有request
* 如果使用线程池:RequestContextHolder.setRequestAttributes(RequestContextHolder.getRequestAttributes(), true);
*/
}
标签:feign,RequestContextHolder,tokenId,requestAttributes,requestTemplate,传递,token,Se From: https://www.cnblogs.com/zhuoneng/p/18071703
}