当前位置: 首页 > 知识库问答 >
问题:

无法使用Spring的Hbase模板从Hbase进行查询

秦焱
2023-03-14
<?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:context="http://www.springframework.org/schema/context"
    xmlns:hdp="http://www.springframework.org/schema/hadoop" xmlns:p="http://www.springframework.org/schema/p"
    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.1.xsd
        http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop-1.0.xsd">


    <bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate"
        p:configuration-ref="hbaseConfiguration" />

        <hdp:configuration>


        </hdp:configuration>


    <hdp:hbase-configuration zk-quorum="hadoop-host-2" zk-port="2181" delete-connection="true">
    </hdp:hbase-configuration>

</beans>
import java.util.List;

import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.data.hadoop.hbase.TableCallback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/hbase/hbase-config.xml")
public class HBaseConnectionTest {

    @Autowired
    private HbaseTemplate hbaseTemplate;

    @Test
    public void testConnection() {

        List<String> list = hbaseTemplate.find("testTab",
                "testcf:testCol", new RowMapper<String>() {

                    @Override
                    public String mapRow(Result result, int arg1)
                            throws Exception {

                        return result.toString();

                    }
                });

        System.out.println(list);

    }

INFO:org.apache.hadoop.hbase.zookeeper.recoverablezookeeper-此进程的标识符为8916@windows-8kv8o4b INFO:org.apache.zookeeper.Client.zookeepersaslClient-Client不会进行SASL身份验证,因为找不到缺省的JAAS配置节“Client”。如果您没有使用SASL,您可以忽略这一点。另一方面,如果您希望SASL能够工作,请修复JAAS配置。信息:org.apache.zookeeper.clientcnxn-建立到IAPS-hadoop-host-2/192.168.111.242:2181的套接字连接,启动会话信息:org.apache.zookeeper.clientcnxn-服务器hadoop-host-2/192.168.111.242:2181上完成会话建立,sessionid=0x13C8BCF1CD7000A,协商超时=60000

共有1个答案

祁宝
2023-03-14

这是失败的,因为我们的hadoop集群中的一些主机无法从我的客户端访问。添加主机名和IP正确地解决了这个问题。

这可能对某人有帮助。

干杯Praveen

 类似资料:
  • 我试图从Windows运行一个HBase Java客户端程序。我所拥有的只有1)一个没有任何编译器错误的Java程序2)hbase-site.xml(我没有其他HDFS或HBase配置文件。只有上面的一个。)当我运行程序时,我得到了以下错误--在最后一个块中给出的。我错过了什么吗?我在这里都给出了。

  • 我想在HBase中执行查询操作,以使用提供的行键列表提取记录。由于MapReduce中的Mappers是并行工作的,所以我想使用它。 行键的输入列表将在~100000的范围内,我已经为映射器创建了一个,它将为每个映射器提供1000行键的列表以查询HBase表。这些查询的记录可能存在于 HBase 表中,也可能不存在,我只想返回那些存在的记录。 我看到了各种各样的例子,我发现hbase table操

  • 我正在通过Java API使用HBase来管理一个URL和参数列表,这些URL和参数等待一个带有多个线程的刮刀进行分析。程序还不断地向表中添加新行。 我需要连续地从表中读取一行并且只读取一行,然后原子地删除它(一行不能同时被两个线程读取),而不需要选择一行而不是另一行的条件。 编辑:我忘了提到表有一个具有单个列的单个列族

  • 一、环境 HBase版本hbase-0.20.5,Hadoop的版本hadoop-0.20.2,JDK1.6 二、需求背景       在HBase中,进行条件查询,很多的文件都说过,但是大多数都是在说明如何设置合理的表结构以及如何设置rowkey进行查询检索,这样的结构设计可以在一定层度上通过rowkey来定位查询(速度很快),但是,如果我是已知某个列的值,需要看有多少行的列包含这个值,那么这样

  • 我在使用Apache HBase构建时遇到以下错误。我正在运行下面的邮件 项目ID:null:akuma:jar:1.9 原因:找不到项目的父级:org.kohsuke:pom:null:akuma:jar:1.9项目的父级:null:akuma:jar:1.9 [INFO]--------------------------------------------------------------

  • 问题内容: 我正在尝试使用SCAN http://redis.io/commands/scan来遍历redis中存在的所有键。但是spring提供的Redis模板没有任何scan()方法。有什么技巧可以使用以上内容吗? 谢谢 问题答案: 您可以使用on 来这样做。