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

相關文章
相關標籤/搜索