在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,并进行数据操作。