Feign Client上的“太多实体参数"异常 [英] 'Too many body parameters' Exception on Feign Client

查看:1362
本文介绍了Feign Client上的“太多实体参数"异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Springs Feign Client功能将一项微服务与另一项微服务进行通信.

I am using Springs Feign Client functionality to communicate from one micro service to another.

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

Now, the called service exposes a REST interface which accepts a file and a related (JSON)Object.

@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) {...}

此接口运行良好,我已经通过从其他来源向其发送有效的多部分/混合实体来对此进行了验证.

This interface is functioning fine, I have verified this by sending a valid multipart/mixed entity to it from a different source.

然后,在我的其他服务中,我已经设置了一个匹配的伪装客户端以使用此界面:

Then, in my other service, I have setup a matching feign client to use this interface:

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

同样,从一项服务到另一项服务的连接正常工作,我已经用伪装客户端中的另一个请求接口(其中一个不使用多个部分)验证了这一点.

Again, the connection from one service to the other is working, Ive verified this with a different request interface in the feign client (one which does not use multiple parts).

当我尝试使用此特定接口方法构建(client)服务时,出现以下异常:

When I try to build the (client)service with this particular interface-method I get the following exception:

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接口,并且不同的伪装调用正在起作用.如果我没记错的话,这应该可行. Springs Feign只是不支持伪装接口的multipart/mixed吗?

Is there anything I can do to make this work? Its possible to reach the REST interface as i stated, and different feign calls are working. If I am not mistaken this should work. Is Springs Feign just not supporting multipart/mixed for feign interfaces?

推荐答案

我刚刚发布了一个自定义的Feign Encoder,可以对多部分请求(一个或多个文件以及json部分)进行编码.您可以在此处尝试.让我知道是否还有其他可用的用例,请随时提出问题.

I just published a custom Feign Encoder that is able to encode multipart requests (one or more files, alongwith json parts). You can try it here. Let me know if there are other use cases that can be implemented, feel free to open issues.

这篇关于Feign Client上的“太多实体参数"异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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