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

一个项目中需要整合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>

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

在 Dart 中,`type 'Image' is not a subtype of type 'Asset' in type cast` 这个错误提示表明你在尝试将一个 `Image` 类型的对象强制转换成 `Asset` 类型,但实际上这两个类型并不是兼容的。`Image` 和 `Asset` 分别代表了图像数据的不同形式: - `Image` 通常是表示已加载到内存中的图像资源,它可以来自网络、本地文件或者是其他来源。 - `Asset` 则是用于存储在应用包内的静态资源,比如图片、音频等,它们是通过 ` AssetImage` 或 `PackageAssetImage` 来访问的。 如果你确实想从 `Image` 转换成 `Asset`,你可能需要检查以下几个点: 1. **是否已经加载完成**:确保你正在转换的 `Image` 实例已经从网络或其他源成功加载并缓存到了内存中,因为只有在这种情况下,它的地址才能映射到一个 `Asset`。 2. **获取 Image 的 source**:如果 `Image` 是从网络请求得到的,你需要先获取其 URL 或者本地路径,然后将其转换为 `Asset`。 3. **转换**:如果你的 `Image` 实例已经有了明确的地址信息,你可以尝试直接创建 ` AssetImage` 或 `PackageAssetImage` 对象,如下所示: ```dart Asset asset = AssetImage(image.getImageUrl()); ``` 这里假设 `getImageUrl()` 返回的是有效的 `Asset` 格式的字符串。 如果你在尝试的操作中,`Image` 并不是由 `Asset` 初始化的,那么直接转换就是不允许的。检查你的代码逻辑,确保操作的类型正确。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

新停浊酒杯

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

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

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

打赏作者

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

抵扣说明:

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

余额充值