您好,欢迎访问一九零五行业门户网

怎么在springboot中集成hbase

依赖:
<dependency>      <groupid>org.springframework.data</groupid>      <artifactid>spring-data-hadoop-hbase</artifactid>      <version>2.5.0.release</version>    </dependency>     <dependency>      <groupid>org.apache.hbase</groupid>      <artifactid>hbase-client</artifactid>      <version>1.1.2</version>    </dependency>     <dependency>      <groupid>org.springframework.data</groupid>      <artifactid>spring-data-hadoop</artifactid>      <version>2.5.0.release</version>    </dependency>
增加配置
官方提供的方式是通过xml方式,简单改写后如下:
@configurationpublic class hbaseconfiguration {   @value(${hbase.zookeeper.quorum})  private string zookeeperquorum;   @value(${hbase.zookeeper.property.clientport})  private string clientport;   @value(${zookeeper.znode.parent})  private string znodeparent;   @bean  public hbasetemplate hbasetemplate() {    org.apache.hadoop.conf.configuration conf = new org.apache.hadoop.conf.configuration();    conf.set(hbase.zookeeper.quorum, zookeeperquorum);    conf.set(hbase.zookeeper.property.clientport, clientport);    conf.set(zookeeper.znode.parent, znodeparent);    return new hbasetemplate(conf);  }}
application.yml:
hbase: zookeeper:  quorum: hadoop001,hadoop002,hadoop003  property:   clientport: 2181 zookeeper: znode:  parent: /hbase
hbasetemplate test :
@service@slf4jpublic class hbaseservice {    @autowired  private hbasetemplate hbasetemplate;    public list<result> getrowkeyandcolumn(string tablename, string startrowkey, string stoprowkey, string column, string qualifier) {    filterlist filterlist = new filterlist(filterlist.operator.must_pass_all);    if (stringutils.isnotblank(column)) {      log.debug({}, column);      filterlist.addfilter(new familyfilter(comparefilter.compareop.equal, new binarycomparator(bytes.tobytes(column))));    }    if (stringutils.isnotblank(qualifier)) {      log.debug({}, qualifier);      filterlist.addfilter(new qualifierfilter(comparefilter.compareop.equal, new binarycomparator(bytes.tobytes(qualifier))));    }    scan scan = new scan();    if (filterlist.getfilters().size() > 0) {      scan.setfilter(filterlist);    }    scan.setstartrow(bytes.tobytes(startrowkey));    scan.setstoprow(bytes.tobytes(stoprowkey));     return hbasetemplate.find(tablename, scan, (rowmapper, rownum) -> rowmapper);  }   public list<result> getlistrowkeydata(string tablename, list<string> rowkeys, string familycolumn, string column) {    return rowkeys.stream().map(rk -> {      if (stringutils.isnotblank(familycolumn)) {        if (stringutils.isnotblank(column)) {          return hbasetemplate.get(tablename, rk, familycolumn, column, (rowmapper, rownum) -> rowmapper);        } else {          return hbasetemplate.get(tablename, rk, familycolumn, (rowmapper, rownum) -> rowmapper);        }      }      return hbasetemplate.get(tablename, rk, (rowmapper, rownum) -> rowmapper);    }).collect(collectors.tolist());  }}
以上就是怎么在springboot中集成hbase的详细内容。
其它类似信息

推荐信息