HBase中报错 java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString

Protobuf(全称 Protocol Buffers)是 Google 开发的一种数据描述语言,可以将结构化数据序列化,可用于数据存储、通讯协议等方面。在 HBase 里面用使用了 Protobuf 的类库。

版本:
HBase:1.3.1
MySQL:8.0.13

错误报告

org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.NoClassDefFoundError: com/google/protobuf/LiteralByteString

缘由分析
运行mvn dependency:tree后发现MySQL8.0.13中有com.google.protobuf:protobuf-java:jar:3.6.1:compile。


查看了3.6.x的protobuf 的源码,里面并无LiteralByteString这个类。
https://github.com/protocolbuffers/protobuf/tree/3.6.x/java/core/src/main/java/com/google/protobuf

查看了2.6.1及如下版本的protobuf 的源码,里面存在LiteralByteString这个类。
https://github.com/google/protobuf/blob/v2.5.0/java/src/main/java/com/google/protobuf/LiteralByteString.java

解决方法尝试
将maven中的MySQL8.0.13的引入注释掉或MySQL版本换成低版本,如5.0.7,能够正常运行。

缘由猜想
应用程序已经得到了另一个版本的Protobuf(如3.6.1)并将其放在类路径中。建议在应用程序上运行mvn dependency:tree以查看它是否正在拾取不兼容的Protobuf依赖项(多是传递性的)。若是应用程序的Maven依赖关系看起来很好,那么当你启动应用程序并拾取一个不正确的Protobuf版本时,多是在运行时重载了类路径。

解决办法
一、下降protobuf版本(实操可用)html

<dependency>
  <groupId>com.google.protobuf</groupId>
  <artifactId>protobuf-java</artifactId>
  <version>2.5.0</version>
</dependency>


二、将客户端的Protobuf类库重命名(尝试了下仍是不行,应该是我自己项目哪还有问题)java

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <relocations>
                    <relocation>
                        <pattern>com.google.protobuf</pattern>
                        <shadedPattern>com.fazi.google.protobuf</shadedPattern>
                    </relocation>
                </relocations>
            </configuration>
        </plugin>
    </plugins>
</build>


三、使用hbase-shaded-client(实操可用)
hbase-shaded-client是社区里有人将HBase里面比较常见的依赖进行了重命名,在pom文件中咱们能够将引入的hbase-client替换成hbase-shaded-clientgit

<dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-shaded-client</artifactId>
            <version>1.3.1</version>
</dependency>


参考地址:
https://stackoverflow.com/questions/41734330/protobuf-error-hbase-createtable-put-in-java-codeprotobuf-literalbytestring
https://www.iteblog.com/archives/2463.html
---------------------
做者:发孖、
来源:CSDN
原文:https://blog.csdn.net/xcf111/article/details/86692591
版权声明:本文为博主原创文章,转载请附上博文连接!github

相关文章
相关标签/搜索