以下代码是同一个服务连接两个不同的hbase集群获取数据
1、pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-common</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-protocol</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
</plugin>
</plugins>
</build>
</project>
2、集群配置文件加载类
package hbase;
import java.util.HashMap;
import java.util.Map;
public class HBaseDaoHolder {
private static volatile HBaseDao BDSE_HBASEDAO = null;
private static volatile HBaseDao BDCSC_HBASEDAO = null;
public static void initAllHbase() {
initBdse();
initBdcsc();
}
/**
* 初始化CDH版Hbase
*/
private static void initBdse() {
// 创建hbasedao
Map<String, String> hbaseConf = new HashMap<String, String>();
String ip = "10.161.1.29,10.161.1.30,10.161.1.31";
hbaseConf.put("hbase.zookeeper.property.maxclientcnxns", "300");
hbaseConf.put("hbase.ipc.client.socket.timeout.connect", "1000");
hbaseConf.put("zookeeper.session.timeout", "500");
hbaseConf.put("hbase.regionserver.handler.count", "500");
hbaseConf.put("hadoop.security.authentication", "kerberos");
hbaseConf.put("hbase.master.kerberos.principal", "hbase/_HOST@KFPT.CTC.LOCAL");
hbaseConf.put("hbase.regionserver.kerberos.principal",