![](/img/trans.png)
[英]How to set value to @RequestAttribute in Spring boot using postman or feign client
[英]How to propagate token using Spring Feign Client
我正在使用 Feign Client 调用另一个微服务,如下所示:
@FeignClient("employee")
public interface EmployeeFeignClient {
@RequestMapping(
method= RequestMethod.GET,
value="/employee/code/{code}",
consumes="application/json"
)
EmployeeResponseEntity getEmployeeByCode(@PathVariable("code") String code);
}
调用员工服务的服务将在其请求 header 中包含身份验证承载令牌。我需要将此相同的令牌传递给正在进行的服务调用。 试图找到如何实现相同但无法实现的方法。 一些帮助会很好。
之前有人回答过。
解决方案是使用@RequestHeader注解,而不是feign特定的注解
@FeignClient(name="Simple-Gateway")
interface GatewayClient {
@RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
String getSessionId(@RequestHeader("X-Auth-Token") String token);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.