gpt4 book ai didi

spring-boot - 将 Feign @HeaderMap 与 Springboot 1.5.4.RELEASE 一起使用不会发送 header

转载 作者:行者123 更新时间:2023-12-05 01:18:31 25 4
gpt4 key购买 nike

我正在尝试使用 feign.HeaderMap 注释在其余请求中传递 HTTP header 的映射,但它们出现在正文中。

代码如下:

@FeignClient(name = "accounts", url = "localhost:8080")公共(public)接口(interface) AccountClient {

@RequestMapping(method = RequestMethod.GET, value = "/rest/accounts/get", produces = MediaType.APPLICATION_JSON_VALUE)
Account findOne(@RequestParam("id") String id, @HeaderMap Map headers);

}

最佳答案

您正在混合注释。使用 spring-cloud-netflix 时,您需要改用 Spring 注释 @RequestHeader

@RequestMapping(method = RequestMethod.GET, 
value = "/rest/accounts/get",
produces = MediaType.APPLICATION_JSON_VALUE)
Account findOne(@RequestParam("id") String id, @RequestHeader Map headers);

Feign中默认所有没有注解的参数都会在Body中序列化。

关于spring-boot - 将 Feign @HeaderMap 与 Springboot 1.5.4.RELEASE 一起使用不会发送 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45233411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com