Hbase API 简单封装

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎转载,转载请注明出处-VirgoArt,

一、Web项目链接配置(这里可以优化成连接池)(关于构造,是为了满足JUnit测试需求)

Hbase API 简单封装

Hbase API 简单封装

package com.pj.util; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; public class HBaseConnectionUtil implements ApplicationListener<ContextRefreshedEvent> { public static Connection connection; private static boolean isCreate = false; public HBaseConnectionUtil() { if (!isCreate) { this.onApplicationEvent(null); } } /** 这里结合Spring配置,实现初始化完成后的消息事件触发 */ @Override public void onApplicationEvent(ContextRefreshedEvent arg0) { if (!isCreate) { Configuration conf = HBaseConfiguration.create(); conf.set(SystemConfigUtil.getInstance().getProValue("HBASE_ZK_PATH"), SystemConfigUtil.getInstance().getProValue("HBASE_ZK_IP")); try { connection = ConnectionFactory.createConnection(conf); } catch (IOException e) { e.printStackTrace(); } isCreate = true; } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyfzsx.html