Describe the bug There are two different clients. It is necessary for each service to send its own headers, which are added via the Interceptor. Only one bin works with two clients at the same time.
Sample
@FeignClient(
name = "service_one",
path = "service_one_path",
configuration = FeignConfigOne.class,
)
public interface ClientOne {
@GetMapping("/one")
Object get();
}
@FeignClient(
name = "service_two",
path = "service_two_path",
configuration = FeignConfigTwo.class,
)
public interface ClientTwo {
@GetMapping("/two")
Object get();
}
@RequiredArgsConstructor
public class FeignConfigOne {
@Bean
public RequestInterceptor oauth2FeignRequestInterceptor() {
return template -> {
String jwtToken = "tokenOne";
template.header(HttpHeaders.AUTHORIZATION, "Bearer " + jwtToken);
};
}
@RequiredArgsConstructor
public class FeignConfigTwo {
@Bean
public RequestInterceptor oauth2FeignRequestInterceptor() {
return template -> {
String jwtToken = "tokenTwo";
template.header(HttpHeaders.AUTHORIZATION, "Bearer " + jwtToken);
};
}
Somewhere in the service call
private ClientOne clientOne;
private ClientTwo clientTwo;
void doCall() {
clientOne.get();
clientTwo.get();
}
Enabled logging shows that the call passes with the same token for both clients
Comment From: DmtryJS
My mistake, there was a transitive dependency where such a bean was already declared