背景
spring程序,使用的feign调用其他服务,结果抛异常:
"Could not write request: no suitable HttpMessageConverter found for request type [com.ekeguan.tradefacade.pojo.req.PhpParams] and content type [application/x-www-form-urlencoded]"}
feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [com.ekeguan.tradefacade.pojo.req.PhpParams] and content type [application/x-www-form-urlencoded]
at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:151)
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:380)
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232)
看一下报错地方的代码:
@RequestMapping(value = "/api/distribute/get"
, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
, method = RequestMethod.POST)
ApiResponse getOrderExpressList(PhpParams params);
解决方法:
@Bean
Encoder feignFormEncoder(ObjectFactory<HttpMessageConverters> converters) {
return new SpringFormEncoder(new SpringEncoder(converters));
}
|