【问题标题】:'Too many body parameters' Exception on Feign ClientFeign 客户端上的“身体参数过多”异常
【发布时间】:2016-03-09 04:45:09
【问题描述】:

我正在使用 Springs Feign Client 功能从一个微服务与另一个微服务进行通信。

现在,被调用的服务公开了一个 REST 接口,该接口接受一个文件和一个相关的 (JSON) 对象。

@RequestMapping(value = {CONVERT_PATH, APPLICATION_PATH + CONVERT_PATH}, method = RequestMethod.POST, produces = CONTENT_TYPE)
    public ResponseEntity<InputStreamResource> convert(@RequestPart("file") MultipartFile file, @RequestParam("input") Input in) {...}

此接口运行良好,我已通过从不同来源向其发送有效的多部分/混合实体来验证这一点。

然后,在我的其他服务中,我设置了一个匹配的 feign 客户端来使用这个接口:

@FeignClient("convert")
public interface ConvertClient {
    @RequestMapping(value = CONVERT_PATH, method = RequestMethod.POST, consumes = "multipart/mixed")
    ResponseEntity<InputStreamResource> convert(@RequestPart("file") MultipartFile file, @RequestPart("input") Input in);
}

再次,从一个服务到另一个服务的连接正常,我已经在 feign 客户端(不使用多个部分)中使用不同的请求接口验证了这一点。

当我尝试使用这个特定的接口方法构建(客户端)服务时,出现以下异常:

FactoryBean threw exception on object creation; 
nested exception is java.lang.IllegalStateException: Method has too many Body parameters: 
public abstract org.springframework.http.ResponseEntity <..>.feign.ConvertClient.convert(org.springframework.web.multipart.MultipartFile,<..>.Input)

我能做些什么来完成这项工作吗? 正如我所说,它可以到达 REST 接口,并且不同的 feign 调用正在工作。如果我没记错的话,这应该可行。 Springs Feign 只是不支持 feign 接口的 multipart/mixed 吗?

【问题讨论】:

    标签: java spring rest netflix-feign


    【解决方案1】:

    我刚刚发布了一个自定义的 Feign 编码器,它能够对多部分请求(一个或多个文件,以及 json 部分)进行编码。你可以试试here。如果还有其他可以实现的用例,请告诉我,请随时打开问题。

    【讨论】:

      猜你喜欢
      • 2019-02-18
      • 2019-07-27
      • 2018-07-22
      • 2019-04-21
      • 2020-01-14
      • 2018-01-05
      • 1970-01-01
      • 2020-01-27
      • 2020-01-08
      相关资源
      最近更新 更多