启动tomcat后,在web controller中不能访问hbase

猿哥 2017-12-06 11:15:42
在junit测试类中,可以访问hbase,但是启动tomcat后,在controller中不能访问hbase,这是怎么回事啊?
这是controller代码:
@Controller
public class CooperateRelaController {

@RequestMapping("/cooperateRela")
public String helloWorld(Model model) {
Configuration configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.quorum","100.66.1.209,100.66.2.1"); //hbase 服务地址
configuration.set("hbase.zookeeper.property.clientPort","2181"); //端口号
HBaseAdmin admin = null;
try {
admin = new HBaseAdmin(configuration);
} catch (IOException e) {
e.printStackTrace();
}
List<String> tables = null;
if (admin != null) {
try {
HTableDescriptor[] allTable = admin.listTables();
if (allTable.length > 0)
tables = new ArrayList<String>();
for (HTableDescriptor hTableDescriptor : allTable) {
tables.add(hTableDescriptor.getNameAsString());
System.out.println(hTableDescriptor.getNameAsString());
}
}catch (IOException e) {
e.printStackTrace();
}
}
return "cooperateRela.ftl";
}
}

异常:


下面是测试类代码:
public class HbaseTest {
private HBaseAdmin admin = null;
// 定义配置对象HBaseConfiguration
private static Configuration configuration;
public HbaseTest() throws Exception {
configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.quorum","100.66.1.209,100.66.2.1"); //hbase 服务地址
configuration.set("hbase.zookeeper.property.clientPort","2181"); //端口号
admin = new HBaseAdmin(configuration);
}
// Hbase获取所有的表信息
public List getAllTables() {
List<String> tables = null;
if (admin != null) {
try {
HTableDescriptor[] allTable = admin.listTables();
if (allTable.length > 0)
tables = new ArrayList<String>();
for (HTableDescriptor hTableDescriptor : allTable) {
tables.add(hTableDescriptor.getNameAsString());
System.out.println(hTableDescriptor.getNameAsString());
}
}catch (IOException e) {
e.printStackTrace();
}
}
return tables;
}
public static void main(String[] args) throws Exception {
HbaseTest hbaseTest = new HbaseTest();
hbaseTest.getAllTables();
}
}

在main函数中可以正常输出,但是启动tomcat后,在浏览器中去访问controller中的代码就不能访问hbase了,这是怎么回事?
...全文
242 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

20,808

社区成员

发帖
与我相关
我的任务
社区描述
Hadoop生态大数据交流社区,致力于有Hadoop,hive,Spark,Hbase,Flink,ClickHouse,Kafka,数据仓库,大数据集群运维技术分享和交流等。致力于收集优质的博客
社区管理员
  • 分布式计算/Hadoop社区
  • 涤生大数据
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧