设为首页 加入收藏

TOP

关于spring集成hbase
2018-11-29 02:39:02 】 浏览:22
Tags:关于 spring 集成 hbase
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhu1361/article/details/38866727

关于spring继承hbase

1.spring继承hbase首先下载spring-data-hadoop jar包官方版本已更新至2.1.0,此处引用1.0.1版本作为继承对象(官方未找到下载端口download点击无反应)。

2.项目中引入spring-data-hadoop jar包。

3.新建一个xml文件命名为applicationContext_hbase.xml在applicationContext.xml中引入此xml文件。

4.配置xml文件 配置内容如下所示:
<xml version="1.0" encoding="UTF-8">

<beansxmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:hdp="http://www.springframework.org/schema/hadoop"

xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/hadoophttp://www.springframework.org/schema/hadoop/spring-hadoop.xsd">

<!-- 配置hadoop的基本信息 -->

<hdp:configuration>

fs.default.name=hdfs://192.168.1.230:9000

</hdp:configuration>

<!-- 配置zookeeper地址和端口 -->

<hdp:hbase-configurationzk-quorum="192.168.1.230"

zk-port="2181"/>

<!-- 配置HbaseTemplate -->

<beanid="htemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">

<propertyname="configuration" ref="hbaseConfiguration">

</property>

</bean>

</beans>
以上就是xml文件配置内容:

5.写方法测试
public static void main(String[]agrs) {

//在xml配置文件中找到htemplate

ApplicationContextcontext = new ClassPathXmlApplicationContext(

newString[] { "applicationContext.xml" });

BeanFactoryfactory = (BeanFactory) context;

HbaseTemplatehtemplate = (HbaseTemplate) factory.getBean("htemplate");

//使用find方法查找 test2为表名 ,zb为列族名称及family

htemplate.find("test2","zb", new RowMapper<String>() {

//result为得到的结果集

publicString mapRow(Result result, int rowNum) throws Exception {

//循环行

for(KeyValue kv : result.raw()) {

//得到列族组成列qualifier

Stringkey = new String(kv.getQualifier());

//得到值

Stringvalue = new String(kv.getValue());

System.out.println(key+ "= "

+Bytes.toString(value.getBytes()));

}

returnnull;

}

});

}

得到结果:

jd= 13

wd= 13

jd= 73

wd= 73

jd= 80

wd= 80

jd= 54

wd= 34

jd= 42

wd= 42

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇HBase常用操作之namespace 下一篇hbase协处理器endpoint应用:hbas..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目