报错:
java.lang.NoClassDefFoundError: Could not initialize class org.apache.hadoop.hbase.util.ByteStringer
原因:
在HBase 1.2.X版本及之前的版本HBase是强依赖于protobuf-2.5.0,如果在依赖中引入高版本的protobuf,会造成hbase的各种问题,所以在有HBase的项目中一定要慎重对待protobuf的版本
解决方法:
本地建一个工程将hbase jar包包裹起来,里面指定protobuf版本
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
<!--[TMS-391] Fix No Such Method Exception when connect HBase -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
</dependency>
</dependencies>
来源:oschina
链接:https://my.oschina.net/u/2000675/blog/3022067