我有安装habse的vm。ip:192.168.20.10我想尝试从桌面连接到hbase:以下是我正在尝试的>
public static void main(String[] args) throws IOException {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hbase-beans.xml", HBaseConnection.class);
context.registerShutdownHook();
UserRepository userRepository = context.getBean(UserRepository.class);
List<User> users = userRepository.findAll();
System.out.println("Number of users = " + users.size());
System.out.println(users);
}
public List<User> findAll() {
return hbaseTemplate.find(tableName, "cfInfo", new RowMapper<User>() {
public User mapRow(Result result, int rowNum) throws Exception {
return new User(Bytes.toString(result.getValue(CF_INFO, qUser)),
Bytes.toString(result.getValue(CF_INFO, qEmail)),
Bytes.toString(result.getValue(CF_INFO, qPassword))
);
}
});
}
这是我的bean.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:hadoop="http://www.springframework.org/schema/hadoop" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.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
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:component-scan base-package="com.hbase.dao"/>
<context:component-scan base-package="com.hbase.object"/>
<hadoop:configuration id="hadoopConfiguration">fs.default.name=hdfs://192.168.20.10:9000</hadoop:configuration>
<hadoop:hbase-configuration configuration-ref="hadoopConfiguration" zk-port="2181" zk-quorum="192.168.20.10"></hadoop:hbase-configuration>
<bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate">
<property name="configuration" ref="hbaseConfiguration" />
</bean>
</beans>
当我直接在远程计算机上运行时,此代码工作正常。当我通过提供hbase的ip从windows计算机上运行相同的代码时,它不会返回任何值。
1条答案
按热度按时间rsaldnfx1#
配置windows计算机
C:\Windows\System32\drivers\etc\hosts
文件来解析您的hbase群集节点详细信息。建议确保dns配置正确!。i、 e.hbase集群的所有节点(RegionServer)的地址都是从windows机器上解析出来的。