How to set request headers using a personalized client?

We are developing a set of microservices using the Spring Cloud infrastructure, and one of the things we need is to set request headers. I know that I can pass the parameter @RequestHeaderto the Feign method, but the value must be obtained from another bean. I do not know if SPEL can be used for the value of the Feign parameter. I thought this was a fairly common use case for most clients, so there are examples, but so far I have not found them. Of course, I can dig through the Spring course code and try to override the default configuration, but it just defeats the goal of the declarative client if I need to write a lot of code for this. Any thoughts?

+4
source share
1 answer

I did this before using RequestInterceptor as follows:

@Component
public class MyRequestInterceptor implements RequestInterceptor {
  @Override
  public void apply(RequestTemplate template) {
    template.headers(getHeadersFromWherever());
  }
}

Here you can find more useful information:

https://github.com/Netflix/feign#user-content-setting-headers-per-target

+5
source

All Articles