not a subtype of implementation type interface org.apache.http.NameValuePair

文章讲述了在项目中整合Elasticsearch和JenkinsAPI时遇到的httpclient版本冲突问题,通过调整依赖版本,最终确定了Elasticsearch和Jenkins所依赖的httpclient版本,解决了兼容性问题。
摘要由CSDN通过智能技术生成

一个项目中需要整合Elasticsearch Java API 以及Jenkins Java API。整个是整合了,最后发现调用的时候Elasticsearch API 调用 后端接口报错。

报错:Invalid receiver type interface org.apache.http.Header; not a subtype of implementation type interface org.apache.http.NameValuePair。

引入的pom依赖:

    <!--elasticsearch API client -->
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.3.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.offbytwo.jenkins/jenkins-client -->
         <!--Jenkins Java API client -->
       <dependency>
            <groupId>com.offbytwo.jenkins</groupId>
            <artifactId>jenkins-client</artifactId>
            <version>0.3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.6</version>
        </dependency>

这个时候调用Elasticsearch API报错如下:

上网查看说是httpclient依赖版本与elasticsearch依赖所依赖的httpclient版本冲突。

解决办法:

打开IDEA,查看Maven依赖

我们发现引入的httpclient依赖是与jenkins所依赖的httpclient版本相同的。再查看elasticsearch-rest-high-level-client所依赖的httpclient,结果如下:

我们看到elasticsearch-rest-high-level-client需要的httpclient依赖版本要求更高,为4.5.8。

调整elasticsearch-rest-high-level-client的版本以及httpclient的版本,使得es以及jenkins API Client所依赖的httpclient兼容

因为jenkins-client的版本最高0.3.8,不能再升,所以选择降es-client版本。

httpclient版本过高jenkins-client会报错:

所以要降低elasticsearch-rest-high-level-client版本到适当程度,使得httpclient版本适中,两者所依赖的httpclient兼容。

文章验证httpclient4.5.2的版本,发现jenkins-client能够正常工作。查看elasticsearch-rest-high-level-client与httpclient的兼容版本对应发现,elasticsearch-rest-high-level-client的6.8.23所依赖的httpclient为4.5.2。所以依赖修改如下:

        <!-- https://mvnrepository.com/artifact/org.elasticsearch/elasticsearch -->
        <!--elasticsearch API client -->
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>6.8.23</version>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>6.8.23</version>
        </dependency>
        <!--jenkins Java API client -->
        <dependency>
            <groupId>com.offbytwo.jenkins</groupId>
            <artifactId>jenkins-client</artifactId>
            <version>0.3.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.15</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

两者得以兼容,问题解决。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

新停浊酒杯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值