0

I am using Feign Client to call another microservice as below:

@FeignClient("employee")
public interface EmployeeFeignClient {

    @RequestMapping(
        method= RequestMethod.GET,
        value="/employee/code/{code}",
        consumes="application/json"
    )
    EmployeeResponseEntity getEmployeeByCode(@PathVariable("code") String code);
}

The service which calls the employee service will have authentication bearer token in its request header. I need to pass this same token to the service call being made. Tried to find on how to achieve the same but could not. Some help would be nice.

GenZ Dev
  • 210
  • 4
  • 16
  • Does this answer your question? [Using @Headers with dynamic values in Feign client + Spring Cloud (Brixton RC2)](https://stackoverflow.com/questions/37066331/using-headers-with-dynamic-values-in-feign-client-spring-cloud-brixton-rc2) – Toni Oct 08 '22 at 08:42

1 Answers1

1

It was answered before.

The solution is to use @RequestHeader annotation instead of feign specific annotations

@FeignClient(name="Simple-Gateway")
interface GatewayClient {    
    @RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
    String getSessionId(@RequestHeader("X-Auth-Token") String token);
}