这是我的 HBase 2.0 示例:
Configuration hBaseConfig = HBaseConfiguration.create();
hBaseConfig.set("hbase.zookeeper.quorum", "192.168.x.xxx");
hBaseConfig.set("hbase.zookeeper.property.clientPort", "2181");
HBaseAdmin.available(hBaseConfig);
Connection connection = ConnectionFactory.createConnection(hBaseConfig);
TableName table1 = TableName.valueOf("test");
Table table = connection.getTable(table1);
CellBuilder cb = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY);
cb.setRow(Bytes.toBytes("row2"));
cb.setFamily(Bytes.toBytes("cf1"));
cb.setQualifier("qualifier1".getBytes());
cb.setValue(Bytes.toBytes("cell_data2"));
cb.setType(Type.Put);
Cell cell = cb.build();
Put p = new Put(Bytes.toBytes("row2"));
p.add(cell);
table.put(p);
connection.close();
我在一个 Spring Boot 2.0 应用程序中编写了上面的演示,gradle 依赖项如下:
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
compile ('org.apache.hbase:hbase:2.0.0')
compile ('org.apache.hbase:hbase-client:2.0.0'){
exclude group :'log4j',module:'log4j'
exclude group :'org.slf4j',module:'slf4j-log4j12'
exclude group: 'javax.servlet', module: 'servlet-api'
}
compile('org.springframework.boot:spring-boot-configuration-processor')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}