基于feign传参MultipartFile问题解决
307
2022-07-23
目录问题说明代码如下解决方案1.由于Hbase自带有zookeeper2.由于这里只是想测试下java连接hbae3.再对zookeeper进行配置 zoo.cfg4.因为是在windows环境下
问题说明
自己用虚拟机安装了Hbase、zookeeper,然后想用javamMxAym访问。
代码如下
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class HbaseTest {
public static void main(String[] args) throws MasterNotRunningException, IOException{
String tableName = "myTest";
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master", "192.168.48.129:16010");
conf.set("hbase.zookeeper.property.clientPort", "2181");
// conf.set("hbase.zookeeper.quorum", "master");
conf.set("hbase.zookeeper.quorum", "192.168.48.129");
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
Get g = new Get(Bytes.toBytes("row1"));
Result result = table.get(g);
byte [] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));
byte[] value1 = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("age"));
table.close();
System.out.println(result.toString());
System.out.println(Bytes.toString(value));
System.out.println(Bytes.toString(value1));
}
}
结果一直卡在result这一样没反应。
解决方案
1.由于Hbase自带有zookeeper
可以先禁用掉自带的zookeeper。
命令:vim hbase/conf/hbase-env.sh
2.由于这里只是想测试下java连接hbae
也并没有搭建Hdoop环境,所以Hbase的hhbase-size.xml配置如下
3.再对zookeeper进行配置 zoo.cfg
4.因为是在windows环境下
用java访问虚拟机的Hbase,所以还需要以下配置
命令:vim /etc/host 添加一行,IP hostname
命令:vim /etc/sysconfig/network-scripts/ifcfg-eth0 ,修改设备名
windows中相应配置:C:\Windows\System32\drivers\etc 在HOST文件中添加IP hostname
所有的配置就到这里结束,启动zookeeper,启动Hbase
java连接Hbase测试
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class HbaseTest {
public static void main(String[] args) throws MasterNotRunningException, IOException{
String tableName = "myTest";
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master", "192.168.48.129:16010");
conf.set("hbase.zookeeper.property.clientPort", "2181");
// conf.set("hbase.zookeeper.quorum", "master");
conf.set("hbase.zookeeper.quorum", "192.168.48.129");
Connection conn = ConnectionFactory.createConnection(conf);
Table table = conn.getTable(TableName.valueOf(tableName));
Get g = new Get(Bytes.toBytes("row1"));
Result result = table.get(g);
byte [] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));
byte[] value1 = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("age"));
table.close();
System.out.println(result.toString());
System.out.println(Bytes.toString(value));
System.out.println(Bytes.toString(value1));
}
}
我个人使用如上方法能够解决连接Hbase无反应的问题。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~