feign.codec.EncodeException: Error converting request body

文章目录

  • 前言
  • 一、错误回顾
    • 1.详细信息
  • 二、解决方案
    • 1.feign代码详情
    • 2.调用代码详情
  • 总结


feign.codec.EncodeException: Error converting request body_第1张图片

前言

最近在做上传文件时,需要调 feign 接口去上传,出了点小差错。feign.codec.EncodeException: Error converting request body。需要在feign接口上加类型以及@RequestPart。


提示:以下是本篇文章正文内容,下面案例可供参考

一、错误回顾

1.详细信息

feign.codec.EncodeException: Error converting request body
	at org.springframework.cloud.openfeign.support.SpringEncoder.encodeWithMessageConverter(SpringEncoder.java:141) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:119) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at org.springframework.cloud.openfeign.support.PageableSpringEncoder.encode(PageableSpringEncoder.java:101) ~[spring-cloud-openfeign-core-2.2.9.RELEASE.jar:2.2.9.RELEASE]
	at feign.ReflectiveFeign$BuildFormEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:358) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232) ~[feign-core-10.12.jar:na]
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:84) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) ~[feign-core-10.12.jar:na]
	at com.sun.proxy.$Proxy216.fileUpload(Unknown Source) ~[na:na]
	at com.sty.resource.web.service.impl.CabinetServiceImpl.importExcel(CabinetServiceImpl.java:120) [classes/:na]

二、解决方案

1.feign代码详情

需要在接口上加类型:
consumes = MediaType.MULTIPART_FORM_DATA_VALUE 以及 @RequestPart(value = “file”)

@PostMapping(value = "/uploadfile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R fileUpload(@RequestPart(value = "file") MultipartFile uploadFile) throws Exception;

2.调用代码详情

需要加上:@RequestPart(value = “file”) 与 feign 接口加的一致

@PostMapping(value = "/uploadfile")
public R fileUpload(@RequestPart(value = "file") MultipartFile uploadFile) throws Exception {...}

总结

别人对你好,那是你的造化,懂得感恩,才有好运气;别人对你不好,那也是你的造化,懂得宽容,才有好心境。

你可能感兴趣的:(错误实例,java,微服务)