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版本時,可能是在運行時重載了類路徑。
解決辦法
1、降低protobuf版本(實操可用)
<dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>2.5.0</version> </dependency>
2、將客戶端的Protobuf類庫重命名(嘗試了下還是不行,應該是我本身項目哪還有問題)
<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>
3、使用hbase-shaded-client(實操可用)
hbase-shaded-client是社區里有人將HBase里面比較常見的依賴進行了重命名,在pom文件中我們可以將引入的hbase-client替換成hbase-shaded-client
<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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!