tablestore依赖问题解决

发布时间 2023-08-21 11:14:09作者: xudong5273

依赖引入最新版本

<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>tablestore</artifactId>
    <version>5.16.0</version>
</dependency>

执行如下方法,报错下面2个错误信息,如下图:

错误一:

错误二:

错误原因:

Java SDK依赖2.4.1版本的Protobuf库和4.0.2版本的httpasyncclient,容易与您的应用程序中自带的相同库冲突。

解决方法:

在Maven项目中的pom.xml中添加如下依赖即可。

classifier为jar-with-dependencies,它将依赖的HttpClient和Protobuf库都通过rename package的方式打包进去,去除了对HttpClient和Protobuf的依赖。
        <dependency>
            <groupId>com.aliyun.openservices</groupId>
            <artifactId>tablestore</artifactId>
            <version>5.16.0</version>
            <classifier>jar-with-dependencies</classifier>
            <exclusions>
                <exclusion>
                    <groupId>com.google.protobuf</groupId>
                    <artifactId>protobuf-java</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.httpcomponents</groupId>
                    <artifactId>httpasyncclient</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
阿里解决方案参考链接:https://help.aliyun.com/zh/tablestore/support/what-do-i-do-if-pb-library-conflicts-occur-when-i-use-tablestore-sdk-for-java?spm=a2c4g.11186623.0.i15