接口定义

报错信息
[org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘’ not supported]
原因
OpenFeign 默认并不支持 multipart/form-data 请求
解决方法
- 接口定义时,需要注意以下几点
a. @PostMapping加入参数:consumes = MediaType.MULTIPART_FORM_DATA_VALUE
b. 请求参数使用:@RequestPart注解 - 添加openFeign支持multipart/form-data 请求配置
@Configuration
public class FeignEncoderConfiguration {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public SpringFormEncoder feignEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}

1439

被折叠的 条评论
为什么被折叠?



