更新时间:2023-04-28 GMT+08:00
分享

创建Configuration

功能介绍

HBase通过加载配置文件来获取配置项。

  1. 加载配置文件是一个比较耗时的操作,如非必要,请尽量使用同一个Configuration对象。
  2. 样例代码未考虑多线程同步的问题,如有需要,请自行增加。其它样例代码也一样,不再一一进行说明。

代码样例

下面代码片段在com.huawei.cloudtable.hbase.examples包中。

private static void init() throws IOException {
  // Default load from conf directory
  conf = HBaseConfiguration.create(); // 注[1]
  String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
  Path hbaseSite = new Path(userdir + "hbase-site.xml");
  if (new File(hbaseSite.toString()).exists()) {
    conf.addResource(hbaseSite);
  }
}

注意事项

  • 注[1] 如果配置文件目录conf已经加入classpath路径中,那么后面的加载指定配置文件的代码可以不执行。
分享:

    相关文档

    相关产品