feign接口
@FeignClient(value = CloudClientConfiguation.PORTAL_PROVIDER_CLOUD)
public interface UserProviderService{
@GetMapping(value = "/user/get-user-info")
PortalFrontRpcResponse<UserRpcBean> getUserInfo(@RequestBody PortalFrontRpcRequest<UserRpcBean> request);
}
服务提供者
@GetMapping(value = "/user/get-user-info")
public PortalFrontRpcResponse<UserRpcBean> getUserInfo(@RequestBody PortalFrontRpcRequest<UserRpcBean> request){
//逻辑略
}
调用时报错
抓包显示post请求
原因
因为Feign默认使用的连接工具实现类,所以里面发现只要你有body体对象,就会强制的把GET请求转换成POST请求。
解决办法
- 更换Apache的HttpClient。
步骤
- 加入Feign的配置项
feign:
httpclient:
enabled: true
- 加入这两个依赖
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.9</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>10.2.3</version>
</dependency>
问题解决!!!