在Spring Boot項目中集成HBase可以通過以下步驟實現:
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>2.3.0</version>
</dependency>
hbase.zookeeper.quorum=zk1,zk2,zk3
hbase.zookeeper.property.clientPort=2181
@Configuration
public class HBaseConfig {
@Value("${hbase.zookeeper.quorum}")
private String zookeeperQuorum;
@Value("${hbase.zookeeper.property.clientPort}")
private String zookeeperClientPort;
@Bean
public Connection hbaseConnection() throws IOException {
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", zookeeperQuorum);
conf.set("hbase.zookeeper.property.clientPort", zookeeperClientPort);
return ConnectionFactory.createConnection(conf);
}
}
@Autowired
private HBaseTemplate hbaseTemplate;
...
Put put = new Put(Bytes.toBytes("rowkey"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("column"), Bytes.toBytes("value"));
hbaseTemplate.put("table", put);
通過以上步驟,就可以在Spring Boot項目中集成HBase,并進行數據操作。