【发布时间】:2020-11-14 03:31:17
【问题描述】:
我在一个服务中有 Feign 客户端和一个方法
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
MyDto uploadDocument(@RequestPart("file") MultipartFile file,
@RequestPart("myDto") String myDto);
我在另一个服务中有一个控制器
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<MyDto> uploadDocument(@RequestParam("file") MultipartFile file,
@RequestPart("myDto") MyDto myDto) {
.... some code here
}
我面临的问题是 Feign 发送 myDto 的 Content-type : text/plain 并且我有 HttpMediaTypeNotSupportedException
是否可以使用 Content-type 发送@RequestPart("myDto") String myDto : application/json ?
预期的原始请求:
----------------------------boundary
Content-Disposition: form-data; name="file"; filename="fileName"
<file>
----------------------------boundary
Content-Disposition: form-data; name="myDto"
**Content-Type: application/json**
{"myDto": ""}
当前原始请求:
----------------------------boundary
Content-Disposition: form-data; name="file"; filename="fileName"
<file>
----------------------------boundary
Content-Disposition: form-data; name="myDto"
**Content-Type: text/plain**
{"myDto": ""}
【问题讨论】:
-
您能否将
Feign客户端中的myDto类型从String更改为MyDto? -
它不起作用,在这种情况下我收到 MissingServletRequestPartException
-
也许这个issue 会有所帮助。你需要使用
feign-form -
谢谢,但他们在控制器中使用字符串。我的目标是使用 MyDto 对象
标签: java spring-cloud-feign feign