Body parameters cannot be used with form parameters - Feign client with Headers and json data

一笑奈何 提交于 2019-12-05 03:36:32

Wow this a tricky one. The order of parameters matter here.

@RequestLine("POST /enroll")
@Headers({ "header1: {header1}", "header2: {header2}", "Content-Type: application/json" })
ResponseDto enroll(RequestDto requestDto, @Param("header1") String header1,@Param("header1") String header1)throws MyCustomException;

This works!!!

Thanks to my senior developer. He found it.

NicolasG

Order of parameters in feign should not matter as stated by spencergibb in this issue : https://github.com/spring-cloud/spring-cloud-netflix/issues/1915. If you don't use form parameters alongside body parameters you should search why one of your parameters is interpreted as a form parameter.

My specific problem, using spring @RequestMapping annotation was that feign was misinterpreting one of my param anotations because of a typo, in my case I provided a request path value /path/{pathParam} and mistype spring annotation with @PathVariable("pathparam") with lower case typo.

I has same error , but not because of order of parameter. Upon investigation found that the problem was in my swagger definition. I had defined parameter definition that was missing missing in path. ie:

     /someapi/bla/{parm1}/bla/
       parameters:
          - $ref: '#/parameters/parm1'
          - $ref: '#/parameters/parm2'

Changed to:

     /someapi/bla/{parm1}/bla/
       parameters:
          - $ref: '#/parameters/parm1'

solved the issue. Hope it helps some one with same issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!