springcloud中微服务之间feign传参
2021-01-05 13:28
标签:super info tor void ati this inter hystrix eth 1、自定义类实现RequestInterceptor接口类: 2、自定义Hystrix的默认隔离策略:网上很多代码例子 3、如果想要把参数通过HTTP请求的header传递到其他服务,就需要另外做些配置,首先你要把参数添加到header里面,然后就可以通过feign传递了,如下: 4、MutableHttpServletRequest是一个工具类: 5、另一个服务在想用的地方接收参数: springcloud中微服务之间feign传参 标签:super info tor void ati this inter hystrix eth 原文地址:https://www.cnblogs.com/dyunfeng/p/12981279.html@Component
public class FeignInterceptor implements RequestInterceptor{
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
template.header("user",request.getHeader("user"));
}
}
}
public class MutableHttpServletRequest extends HttpServletRequestWrapper {
// holds custom header and value mapping
private final Map
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String userStr = request.getHeader("user");
文章标题:springcloud中微服务之间feign传参
文章链接:http://soscw.com/index.php/essay/40271.html