feign调用服务报异常feign.Response.create(ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)Lfeign/Res

openfeign里面配置httpclient出错。
因为现在需要使用get方式传递对象参数,所以尝试在openfeign里面配置httpclient。
配置代码如下:
在yml文件里面增加了配置信息

feign:
httpclient:
enabled: true
在pom.xml文件中引入的依赖:

   <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.3</version>
    </dependency>
    <!-- 使用Apache HttpClient替换Feign原生httpclient -->
    <dependency>
        <groupId>com.netflix.feign</groupId>
        <artifactId>feign-httpclient</artifactId>
        <version>8.16.1</version>
    </dependency>

配置好以后尝试使用get方式传递对象参数。
服务提供端代码:

@GetMapping(value = “testAddRole1”,consumes = “application/json”)
public JsonResult addTest1(@RequestBody Role role){
roleService.addRole(role);
return JsonResult.getInstant(ReturnCodeEnum.SUCCESS);
}
服务调用接口为:

@GetMapping(value = “/testAddRole1”,consumes = “application/json”)
JsonResult testAddRole1(@RequestBody Role role);
现在在尝试调用接口后发现服务提供方可以接受到参数并且能够写到数据库中,但是在服务调用方拿不到正确的返回值并且会报错,错误如下:

Caused by: java.lang.NoSuchMethodError: feign.Response.create(ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)Lfeign/Response;
查看源码得知,openfeign在接受返回值时调用的不是httpclient的feign-core包的代码而是调用的本身的feign-core的代码,而本身的feign-core包中的Response类没有create方法。
得知原因后我将httpclient的依赖在pom文件中的位置上移,使openfeign优先调用httpclient的feign-core包的代码,结果在启动项目时就报错,报错信息为:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘test1Controller’ defined in file [D:\workspace\basic\openfeign\target\classes\cn\cloudscope\openfeignTest\Test1\controller\Test1Controller.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘cn.cloudscope.openfeignTest.Test1.service.Test1Service’: FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘feignRetryer’ defined in org.springframework.cloud.openfeign.FeignClientsConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [feign.Retryer]: Factory method ‘feignRetryer’ threw exception; nested exception is java.lang.NoSuchFieldError: NEVER_RETRY

查看原因得知是两个feign-core包中的Retryer接口不一致导致的,求来个大神帮忙解决一下,或者怎么调整jar包的版本去解决这个问题。openfeign的feign-core版本为10.1.0 httpclient的版本为8.16.1

我也遇到了这个问题,把你的feign-httpclient依赖换成这个

io.github.openfeign feign-httpclient 10.1.0 说明feign-httpclient 10.0以上版本有更新!
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值