最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论