使用Feign @HeaderMap与Springboot 1.5.4.RELEASE一起使用时无法发送头信息。

3

我试图使用feign.HeaderMap注解在rest请求中传递一个包含HTTP头的映射,但这些出现在正文中。

以下是代码:

@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);

}

1个回答

8

您混合了注释。在使用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);
< p >在Feign中,默认情况下,未注释的所有参数都将序列化到请求体中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接