Feign客户端出现“参数过多”异常

5

我正在使用Spring的Feign客户端功能来实现微服务之间的通信。

现在,被调用的服务公开了一个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) {...}

这个接口运行正常,我通过从不同来源发送一个有效的multipart/mixed实体来验证了它的功能。

然后,在我的另一个服务中,我设置了一个匹配的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调用都在工作。如果我没有弄错的话,这应该能行。 Spring的Feign的接口不支持multipart/mixed吗?

1个回答

1
我刚刚发布了一个自定义的Feign编码器,能够编码多部分请求(一个或多个文件,以及json部分)。你可以在这里尝试。如果有其他可实现的用例,请随意提出问题。

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