如題,網上都有做法,只有有些人說的不清楚。而我自己也遇到了其他坑這里記錄一下
1.就是網上說的做法:
客戶端:application.yml加上配置:
feign:
httpclient:
enabled: true
請求接口上
@RequestMapping(method = RequestMethod.GET,value = "***",consumes = ("application/json"))
ResultVo<List<Goods>> selectGoods(Goods goods);
pom上:
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <!--使用Apache HttpClient替換Feign原生httpclient--> <dependency> <groupId>io.github.openfeign</groupId> <artifactId>feign-httpclient</artifactId> <version>10.0.1</version> </dependency>
服務端:接口參數上加上 @RequestBody 注解
2.自己遇到的坑:
一開始不知道為什么,請求還是不行,依舊調用jdk的HttpURLConnection 的 getOutputStream0 方法(想判斷feign.httpclient.enalble是否生效,可以在方法里打斷點)。之后嘗試了其他解決方式,發現報錯沒有feign.httpclient.ApacheHttpClient類,查找一下果然沒有這個類,原來之前pom沒有把jar導進來。使用上面的方法,reimport jar包~done!