Unable to create ZooKeeper Connection

我使用HBase API试图创建一个Table,但是抛出了如下异常:
Unable to create ZooKeeper Connection
java.io.IOException: Couldn't instantiate org.apache.zookeeper.ClientCnxnSocketNIO

我的代码如下:

package GroupHBase.HBaseTest;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.log4j.spi.Configurator;
import org.junit.jupiter.api.Test;

public class PutTest {


static HBaseAdmin admin;
static String TableName="haha";


public static void init() throws Exception{
Configuration conf=new Configuration();
conf.set("hbase.zookeeper.quorum", "tuge2,tuge3,tuge4");
admin=new HBaseAdmin(conf);
}

@Test
public static void createTable() throws Exception {

HTableDescriptor desc=new HTableDescriptor(TableName.valueOf(TableName)); 
HColumnDescriptor cf=new HColumnDescriptor("cf".getBytes());
desc.addFamily(cf);
admin.createTable(desc);

}



public static void main(String[] args) throws IOException {
try {
init();
createTable();
System.out.println("zj...");
}
catch(Exception ex){
ex.printStackTrace();
}


}

}

我Hadoop和ZooKeeper里面的Jar包都引入了。
Hadoop版本是2.6.5
ZooKeeper版本是3.5.5
纠结了一天,刚开始使用的是官网的Demo,后来出现上述异常后搜的网上的Demo报了同样错误。 谁能帮帮我 🙂

阅读 616
评论 2019-11-21 提问
    撰写回答

    登录后参与交流、获取后续更新提醒