腾讯云环境下Feign调用异常(okhttp)

问题描述

在腾讯云环境中,代码存在feign调用,不用默认的client要启用okHttpClient,支持okhttp请求,以实现请求支持连接池和请求压缩,来提升请求和响应速度,但是在导入相关的依赖开启okhttp配置后,测试返现feign调用异常,java.lang.NoClassDefFoundError: feign/Request$HttpMethod,我又把okhttp的配置关了,启用默认的client,调用成功。由此可见,是ohhttp的问题,请各位一起出谋划策。

导入的依赖如下,已排除依赖冲突
      <dependency>
          <groupId>org.springframework.cloudgroupId>
          <artifactId>spring-cloud-openfeignartifactId>
      dependency>
      
      
      <dependency>
          <groupId>io.github.openfeigngroupId>
          <artifactId>feign-okhttpartifactId>
          <version>11.8version>
          <exclusions>
              <exclusion>
                  <artifactId>feign-coreartifactId>
                  <groupId>io.github.openfeigngroupId>
              exclusion>
              <exclusion>
                  <artifactId>kotlin-stdlibartifactId>
                  <groupId>org.jetbrains.kotlingroupId>
              exclusion>
              <exclusion>
                  <artifactId>kotlin-stdlib-commonartifactId>
                  <groupId>org.jetbrains.kotlingroupId>
              exclusion>
          exclusions>
      dependency>

      <dependency>
          <groupId>org.jetbrains.kotlingroupId>
          <artifactId>kotlin-stdlibartifactId>
          <version>1.3.70version>
          <exclusions>
              <exclusion>
                  <artifactId>annotationsartifactId>
                  <groupId>org.jetbrainsgroupId>
              exclusion>
          exclusions>
      dependency>
okhttp的配置
feign:
  client:
    config:
      default:
        connectTimeout: 20000
        readTimeout: 30000
  httpclient:
    enabled: false
  okhttp:
    enabled: true
  compression:
    request:
      enabled: true #开启请求压缩
      mime-types: text/html,application/xml,application/json #设置压缩的数据类型
      min-request-size: 2048 #设置触发压缩的大小下限
    response:
        enabled: true #开启响应压缩
运行结果及报错内容 ,这个错误在服务启动后的每一次feign(okhttp请求)都会报错

img

运行结果及报错内容 ,这个错误只在服务启动后的第一次feign调用(okhttp请求)会报这个错

img

可以看到确实是okhttpclient,并支持连接池

img

到这里再往下执行就会报错上述错误了

img

不需要排除依赖,只需要添加配置feign.okhttp.enabled=true

参考,亲测正确https://blog.csdn.net/qq_43437874/article/details/122169675