Spring Cloud Feign Client @RequestParam with List 参数创建错误请求 [英] Spring Cloud Feign Client @RequestParam with List parameter creates a wrong request

查看:38
本文介绍了Spring Cloud Feign Client @RequestParam with List 参数创建错误请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Spring Clound Feign Client 映射定义如下

I have a Spring Clound Feign Client mapping defined as following

@RequestMapping(method = RequestMethod.GET, value = "/search/findByIdIn")
Resources<MyClass> get(@RequestParam("ids") List<Long> ids);

当我打电话

feignClient.get(Arrays.asList(1L,2L,3L))

根据我在调试器中看到的,feign-core 库形成了如下请求:

according to what I can see in the debugger, the feign-core library forms the following request:

/search/findByIdIn?ids=1&ids=2&ids=3

而不是预期

/search/findByIdIn?ids=1,2,3

这对于以与我的 Feign 客户端方法相同的方式声明的服务器 Spring Data REST 端点是正确的.

which would be correct for the server Spring Data REST endpoint declared in the same way as my Feign client method.

因此,由于这个问题,请求总是返回空集.

Thus, because of this issue, the request always returns empty set.

我见过类似的问题,但看起来像Feign 客户端在 2015 年按我的预期工作.

I have seen similar question, but it looks like the Feign client was working as I expect back in 2015.

我正在使用:

  • spring-cloud-starter-feign 版本 1.2.4.RELEASE
  • feign-httpclient 版本 9.4.0
  • 伪装核心版本 9.4.0

有没有办法纠正行为并将 Spring Cloud Feign Client 与 Spring Data REST 定义的端点结合"?

Is there a way to correct the behaviour and "marry" the Spring Cloud Feign Client with the Spring Data REST defined endpoints?

推荐答案

我遇到了同样的问题,多次出现参数而不是预期的逗号分隔的项目序列.解决方案非常简单:

I had the same issue with multiple occurence of the parametre instead of the expected comma separated sequence of items. The solution was really simple:

在我的 feign 客户端中,我使用了数组

In my feign client I used arrays

feignClient.get(new Long[]{1L,2L,3L})

而不是集合/列表:

feignClient.get(Arrays.asList(1L,2L,3L))

这篇关于Spring Cloud Feign Client @RequestParam with List 参数创建错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆