1、hbase.properties文件:
quorum=10.46.60.**
clientPort=*****
2、spring-hbase.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:hdp="http://www.springframework.org/schema/hadoop"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">
<!-- 加载外部的properties配置文件 -->
<context:property-placeholder location="file:/opt/search/resourse/hbase.properties"/>
<!-- 配置zookeeper的信息,远程连接hbase时使用 -->
<hdp:configuration resources="classpath:/hbase-site.xml" />
<hdp:hbase-configuration zk-quorum="${quorum}"
zk-port="${clientPort}" configuration-ref="hadoopConfiguration" /> <!--这里特别要注意,只有 zk-quorum和zk-port从hbase.properties获取,其他配置在hbase-site.xml-->
<!-- 配置HbaseTemplate -->
<bean id="htemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">
<property name="configuration" ref="hbaseConfiguration">
</property>
<property name="encoding" value="UTF-8"></property>
</bean>
</beans>
3、hbase-site.xml文件
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- zookeeper集群的URL配置
<property>
<name>hbase.zookeeper.quorum</name>
<value>namenode1-sit.cnsuning.com,namenode2-sit.cnsuning.com,slave01-sit.cnsuning.com</value>
</property> -->
<!-- 客户端连接端口
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2015</value>
</property>-->
<!-- 重试等待时间 -->
<property>
<name>hbase.client.pause</name>
<value>50</value>
</property>
<!-- 失败时重试次数 -->
<property>
<name>hbase.client.retries.number</name>
<value>3</value>
</property>
<!-- RPC请求的超时时间。如果某次RPC时间超过该值,客户端就会主动关闭socket -->
<property>
<name>hbase.rpc.timeout</name>
<value>2000</value>
</property>
<!-- HBase客户端发起一次数据操作直至得到响应之间总的超时时间 -->
<property>
<name>hbase.client.operation.timeout</name>
<value>3000</value>
</property>
<!-- 该参数是表示HBase客户端发起一次scan操作的rpc调用至得到响应之间总的超时时间 -->
<property>
<name>hbase.client.scanner.timeout.period</name>
<value>10000</value>
</property>
</configuration>
4、在java中应用
static private ApplicationContext hbaseContext = new ClassPathXmlApplicationContext("classpath:spring-hbase.xml");
static private BeanFactory factory = (BeanFactory) hbaseContext;
static private HbaseTemplate htemplate = (HbaseTemplate) factory.getBean("htemplate");
注意:利用这种方式的缺陷:利用Spring获取hbase.properties文件的配置无法实现实时获取