Spring Feign: how to add a correlation token header value from MDC context? - Stack Overflow

Given the following Feign client:@FeignClient(value="myClient", url="https:someurl&qu

Given the following Feign client:

@FeignClient(value="myClient", url="https://someurl", configuration=config.class)
public interface myClient {
  @RequestMapping(method=Request.Method.GET, value="/somepath")
  SomeResponse getSomething();
}

and this config:

@Configuration
public class config{
    @Bean
    public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new BasicAuthRequestInterceptor("username", "password");
    }
}

How could we add a header X-CorrelationToken with a value of MDC.get("token"), Specifically, we don't want to have to pass the token as a parameter to each Feign call, as we have hundreds.

I tried this:

@FeignClient(value="myClient", url="https://someurl", configuration=config.class)
@Headers("X-CorrelationToken: {MDC.get(\"token\")}")
public interface myClient {

Presumably it can be done with an interceptor, but how can I add two interceptors, given it already uses the BasicAuthRequestInterceptor?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742342775a4425960.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信