【feign】Could not write request: no suitable HttpMessageConverter found for request type

川长思鸟来 2022-09-14 02:26 444阅读 0赞

背景

spring程序,使用的feign调用其他服务,结果抛异常:

  1. "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]"}
  2. 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]
  3. at org.springframework.cloud.openfeign.support.SpringEncoder.encode(SpringEncoder.java:151)
  4. at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:380)
  5. at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:232)

看一下报错地方的代码:

  1. @RequestMapping(value = "/api/distribute/get"
  2. , consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
  3. , method = RequestMethod.POST)
  4. ApiResponse getOrderExpressList(PhpParams params);

解决方法:

  1. @Bean
  2. Encoder feignFormEncoder(ObjectFactory<HttpMessageConverters> converters) {
  3. return new SpringFormEncoder(new SpringEncoder(converters));
  4. }

发表评论

表情:
评论列表 (有 0 条评论,444人围观)

还没有评论,来说两句吧...

相关阅读