关于spring集成hbase
来源:互联网 发布:java 两个时间戳相减 编辑:程序博客网 时间:2024/05/29 17:09
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"?><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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/hadoop http://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-configuration zk-quorum="192.168.1.230"zk-port="2181" /><!-- 配置HbaseTemplate --><bean id="htemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate"><property name="configuration" ref="hbaseConfiguration"></property></bean></beans>
以上就是xml文件配置内容:
5.写方法测试
public static void main(String[] agrs) {//在xml配置文件中找到htemplateApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "applicationContext.xml" });BeanFactory factory = (BeanFactory) context;HbaseTemplate htemplate = (HbaseTemplate) factory.getBean("htemplate");//使用find方法查找 test2为表名 ,zb为列族名称及familyhtemplate.find("test2", "zb", new RowMapper<String>() {//result为得到的结果集public String mapRow(Result result, int rowNum) throws Exception {//循环行for (KeyValue kv : result.raw()) {//得到列族组成列qualifierString key = new String(kv.getQualifier());//得到值String value = new String(kv.getValue());System.out.println(key + "= "+ Bytes.toString(value.getBytes()));}return null;}});}
得到结果:
jd= 13
wd= 13
jd= 73
wd= 73
jd= 80
wd= 80
jd= 54
wd= 34
jd= 42
wd= 42
0 0
- 关于spring集成hbase
- 关于spring集成hbase
- spring+hbase集成
- spring+hbase集成
- Spring Boot 集成MyBatis 访问Hbase-Phoenix
- 集成hbase
- spring集成hbase以及所遇到的问题
- 关于Spring集成JSF是的问题
- 关于 spring IOC容器的集成
- 关于spring与EHcache的集成
- 关于Spring集成Quartz的concurrent属性
- 关于spring+struts+hibernate集成的问题
- 关于Spring集成Quartz的concurrent属性
- 关于Spring集成Quartz的concurrent属性
- 关于Spring集成Quartz的concurrent属性
- 关于Spring集成Quartz的concurrent属性
- 关于Spring集成Quartz的concurrent属性
- Hive与HBase集成
- 软件开发管理工具--持续集成构建
- 第十二周 求出图G中出度最大的一个顶点,输出该顶点编号
- LeetCode Longest Valid Parentheses
- AVAudioPlayerz小示例
- HTTP协议总结
- 关于spring集成hbase
- LeetCode Search in Rotated Sorted Array II
- fragment 不调用 onActivityResult
- Android:AlertDialog.Builder创建常见对话框
- ubuntu安装jdk
- 数据结构:树
- 用Android Studio通过Java代码调用C代码的JNI流程
- 逐渐变暗
- 抓取网页相关方法