我设法使用以下方法集成Hbase
到Spring
应用程序中HbaseTemplate
:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class ItemRepositoryImpl implements ItemRepository {
@Autowired
private HbaseTemplate hbaseTemplate;
@Override
public List<Item> findAll() {
Scan scan = new Scan();
scan.addColumn(CF, CQ);
hbaseTemplate.find("TABLE_NAME", scan, (result, rowNum) -> {
return new Item(...)
});
}
}
但是,每次运行时都会打开与 Hbase 的连接findAll()
(并在之后关闭)。我在某处读到保持连接活动的方法是使用Connection
和Table
调用 Hbase。问题是HbaseTemplate
使用HConnection
and HTableInterface
。
我怎样才能让我的连接保持活跃HbaseTemplate
?启动新连接非常耗时,我只想做一次。或者还有其他方法可以从Spring
应用程序连接到 Hbase 吗?
我正在使用:
org.springframework.data:spring-data-hadoop:2.5.0.RELEASE
org.apache.hbase:hbase-client:1.1.2