2017-04-24 46 views
1

我有一個FeignClient這樣車身參數不能與形式參數一起使用 - 假裝客戶端頭和JSON數據

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

` 我不使用春雲Netflix的。但我不斷得到下面的例外。

Caused by: java.lang.IllegalStateException: Body parameters cannot be used with form parameters. 
at feign.Util.checkState(Util.java:128) 
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:112) 
at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64) 
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146) 
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53) 
at feign.Feign$Builder.target(Feign.java:209) 
at feign.Feign$Builder.target(Feign.java:205) 

我正在實例化我的客戶端。

return Feign.builder() 
     .encoder(new JacksonEncoder()) 
     .decoder(new JacksonDecoder()) 
     .logger(new Slf4jLogger()) 
     .logLevel(Logger.Level.FULL) 
     .target(RegularFeignClient.class, url); 

回答

3

哇這是一個棘手的問題。參數的順序在這裏很重要。

@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; 

這工作!

感謝我的高級開發人員。他找到了。