前提:1.连接hadoop需要本地安装 winutils.exe 并在程序指定,不然程序会报错  IOException: HADOOP_HOME or hadoop.home.dir are not set. 但不指定程序可能启动。

2.要在springboot容器启动后再初始化页面,否则使用时会取不到bean

整体思路:程序启动时,扫描所有包的@Configation,有使用到自定义的配置可以用@Value映射变量

HBASE读取配置:因为涉及到的配置较多,有两种方式可以考虑,最终注入,反转来调用的只有两个变量  admin、connetion来实现查询和持久化功能

第一种方式:通过xml配置文件,命名一定要hbase-site.xml(还有一个hbase-defualt.xml),这样在装载 org.apache.hadoop.conf.Configuration时程序就会自动读取resource下的xml文件封装。

第二种方式:通过yml配置信息,但不用所有变量都取出来;写一个工具类,IntegrateHBaseProperties指定hbase配置的父路径,并写一个config的set方法,定义一个map变量;在读取配置类里启动这个类                                  @EnableConfigurationProperties(IntegrateHBaseProperties.class),数据就自动封装到map变量里,再用set方法读取放在org.apache.hadoop.conf.Configuration里;

ORACLE以及IMPALA配置:这两者是一样的,这里都用读取yml中的配置,拿到dataSource和jdbcTemplate,而jdbcTemplate这个类里就有我们所有想要的操作了;

下面代码只贴一些主要的,源码是我用swing写的一个多配置连接数据库工具,已上传到百度网盘上

启动类:HbaseApplication
@SpringBootApplication
public class HbaseApplication { public static void main(String[] args) throws IOException {
File workaround = new File(".");
System.getProperties().put("hadoop.home.dir", workaround.getAbsolutePath());
new File("./bin").mkdirs();
new File("./bin/winutils.exe").createNewFile();
System. setProperty("java.awt.headless", "false");
SpringApplication app = new SpringApplication(HbaseApplication.class);
app.addListeners(new ApplicationStartup());
app.run(args);
} }

配置文件:application.yml

hbase:
local:
config:
hbase.zookeeper.quorum: ddatanode17222.ifoton.com.cn,dnamenode17226.ifoton.com.cn,ddatanode17224.ifoton.com.cn,dnamenode17225.ifoton.com.cn,ddatanode17223.ifoton.com.cn
hbase.zookeeper.property.clientPort: 2181
hbase.rest.ssl.enabled: false
hbase.rpc.protection: authentication
hbase.security.authentication: simple
hbase.snapshot.master.timeout.millis: 60000
hbase.snapshot.region.timeout: 60000
hbase.snapshot.master.timeoutMillis: 60000
hbase.snapshot.enabled: true
hbase.rpc.timeout: 60000
hbase.thrift.support.proxyuser: false
hbase.regionserver.thrift.http: false
hbase.coprocessor.region.classes: org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint
hbase.client.scanner.timeout.period: 60000
hbase.fs.tmp.dir: /user/${user.name}/hbase-staging
hbase.client.primaryCallTimeout.multiget: 10
hbase.client.primaryCallTimeout.get: 10
hbase.ipc.client.allowsInterrupt: true
hbase.client.keyvalue.maxsize: 10485760
hbase.client.scanner.caching: 100
hbase.client.retries.number: 35
hbase.client.pause: 100
hbase.client.write.buffer: 2097152
hbase.rootdir: hdfs://nameservice226/hbase
zookeeper.znode.rootserver: root-region-server
zookeeper.session.timeout: 60000
integrate:
config:
hbase.zookeeper.quorum: pdatanode66.ifoton.com.cn,pdatanode64.ifoton.com.cn,pdatanode63.ifoton.com.cn,pdatanode65.ifoton.com.cn,pnamenode62.ifoton.com.cn
hbase.zookeeper.property.clientPort: 2181
hbase.rest.ssl.enabled: false
hbase.rpc.protection: authentication
hbase.security.authentication: simple
hbase.snapshot.master.timeout.millis: 60000
hbase.snapshot.region.timeout: 60000
hbase.snapshot.master.timeoutMillis: 60000
hbase.snapshot.enabled: true
hbase.rpc.timeout: 60000
hbase.thrift.support.proxyuser: false
hbase.regionserver.thrift.http: false
hbase.coprocessor.region.classes: org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint
hbase.client.scanner.timeout.period: 60000
hbase.client.primaryCallTimeout.multiget: 10
hbase.client.primaryCallTimeout.get: 10
hbase.ipc.client.allowsInterrupt: true
hbase.client.keyvalue.maxsize: 10485760
hbase.client.scanner.caching: 100
hbase.client.retries.number: 35
hbase.client.pause: 100
hbase.client.write.buffer: 2097152
hbase.rootdir: hdfs://nameservice1/hbase
zookeeper.znode.rootserver: root-region-server
zookeeper.session.timeout: 60000 impala:
url: jdbc:impala://172.24.17.158:21050/default;AuthMech=0;SocketTimeout=0
port: 21050
schema: default
user: impala
password: impala
driverClass: com.cloudera.impala.jdbc41.Driver
url2: jdbc:impala://10.100.62.61:21050/default;AuthMech=0;SocketTimeout=0 spring:
freemarker:
cache: false
charset: utf-8
enabled: true
datasource:
type: com.alibaba.druid.pool.DruidDataSource
max-idle: 10
max-wait: 10000
min-idle: 5
initial-size: 5
integrate:
driver-class-name: oracle.jdbc.OracleDriver
username: foton
password: 3UI%die)e2_2urYUCN
jdbc-url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.100.58.218)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=iovdb)))
type: ORACLE
local:
driver-class-name: oracle.jdbc.OracleDriver
username: foton
password: 7Ca30Rt
jdbc-url: jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.24.7.189)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=iovdb)))
type: ORACLE

配置类:ImpalaConfig:

@Configuration
public class ImpalaConfig {
@Value("${impala.url}")
private String impalaUrl;
@Value("${impala.url2}")
private String impalaUrl2;
@Value("${impala.port}")
private String impalaPort;
@Value("${impala.schema}")
private String impalaScheme;
@Value("${impala.user}")
private String impalaUser;
@Value("${impala.password}")
private String impalaPassword; @Bean(name = {"impalaJdbcTemplate"})
@Qualifier("impalaJdbcTemplate")
public JdbcTemplate getImpalaJdbcTemplate() {
String connUrl = this.impalaUrl + ":" + this.impalaPort + "/" + this.impalaScheme + ";auth=noSasl";
DataSource dataSource = new DataSource();
dataSource.setURL(connUrl);
return new JdbcTemplate(dataSource);
} @Bean(name = {"impalaJdbcTemplate2"})
@Qualifier("impalaJdbcTemplate2")
public JdbcTemplate getImpalaJdbcTemplate2() {
String connUrl = this.impalaUrl2 + ":" + this.impalaPort + "/" + this.impalaScheme + ";auth=noSasl";
DataSource dataSource = new DataSource();
dataSource.setURL(connUrl);
return new JdbcTemplate(dataSource);
}
配置类2:IntegrateHBaseConfig:
@Configuration
@EnableConfigurationProperties(IntegrateHBaseProperties.class)
public class IntegrateHBaseConfig { private final IntegrateHBaseProperties properties; public IntegrateHBaseConfig(IntegrateHBaseProperties properties) {
this.properties = properties;
} @Bean(name = "integrateHBaseService")
@Qualifier("integrateHBaseService")
@Primary
public HBaseService integrateHBaseService() {
org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
Map<String, String> config = properties.getConfig();
Set<String> keySet = config.keySet();
for (String key : keySet) {
conf.set(key, config.get(key));
}
return new HBaseService(conf);
} }

配置类3:LocalHBaseConfig

@Configuration
@EnableConfigurationProperties(LocalHBaseProperties.class)
public class LocalHBaseConfig { private final LocalHBaseProperties properties; public LocalHBaseConfig(LocalHBaseProperties properties) {
this.properties = properties;
} @Bean(name = "localHBaseService")
@Qualifier("localHBaseService")
@Primary
public HBaseService localHBaseService() {
org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
Map<String, String> config = properties.getConfig();
Set<String> keySet = config.keySet();
for (String key : keySet) {
conf.set(key, config.get(key));
}
return new HBaseService(conf);
} }

配置类4:OracleConfig

@Configuration
public class OracleConfig {
//@Primary注解在哪个ds,默认使用那个ds @Bean(name = "integrateDataSource")
@Qualifier("integrateDataSource")
@ConfigurationProperties(prefix="spring.datasource.integrate")
public DataSource integrateDataSource() {
return DataSourceBuilder.create().build();
} @Bean(name = "localDataSource")
@Qualifier("localDataSource")
@Primary
@ConfigurationProperties(prefix="spring.datasource.local")
public DataSource localDataSource() {
return DataSourceBuilder.create().build();
} @Bean(name = "integrateJdbcTemplate")
public JdbcTemplate integrateJdbcTemplate(
@Qualifier("integrateDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
} @Bean(name = "localJdbcTemplate")
public JdbcTemplate localJdbcTemplate(
@Qualifier("localDataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
} }

业务类:DBService

@Service
public class DBService { @Autowired
@Qualifier("localHBaseService")
HBaseService localHBaseService;
@Autowired
@Qualifier("integrateHBaseService")
HBaseService integrateHBaseService;
@Autowired
@Qualifier("localJdbcTemplate")
JdbcTemplate localJdbcTemplate;
@Autowired
@Qualifier("impalaJdbcTemplate")
JdbcTemplate impalaJdbcTemplate;
@Autowired
@Qualifier("impalaJdbcTemplate2")
JdbcTemplate impalaJdbcTemplate2;
@Autowired
@Qualifier("integrateJdbcTemplate")
JdbcTemplate integrateJdbcTemplate; 。。。
}
 

SpringBoot连接多数据源(HBASE,KUDU,ORACLE集成和开发库)的更多相关文章

  1. SpringBoot添加多数据源mysql和oracle

    项目结构 多数据源配置文件 MultiDataSourceConfig.java SqlSessionTemplate1.java SqlSessionTemplate2.java package c ...

  2. Oracle连接odbc数据源

    Oracle连接odbc数据源 说明 oracle连接ODBC数据源有两种方式,hsodbc和dg4odbc,简单说dg4odbc是hsodbc的升级.两种连接方法大致一样,现将连接步骤说明如下: 检 ...

  3. springboot添加多数据源连接池并配置Mybatis

    springboot添加多数据源连接池并配置Mybatis 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/9190226.html May 12, 2018  ...

  4. Springboot+Mybatis+Pagehelper+Aop动态配置Oracle、Mysql数据源

      本文链接:https://blog.csdn.net/wjy511295494/article/details/78825890 Springboot+Mybatis+Pagehelper+Aop ...

  5. Superset连接Impala数据源

    公司最近在superset上面做二次开发,目前对接了mysql和oracle数据源,对这两个源的SQL操作查询做了完善和兼容.目前有新的需求就是要对接大数据部门的HBASE和HIVE数据源,由于sup ...

  6. springboot+ibatis 多数据源配置

    这个是boot基本版本包,因为我用的打包方式是war所以去除掉了boot内置的tomcat,但是为了方便测试又引入了内置tomcat,只要添加<scope>provided</sco ...

  7. SpringBoot配置多数据源时遇到的问题

    SpringBoot配置多数据源 参考代码:Spring Boot 1.5.8.RELEASE同时配置Oracle和MySQL 原作者用的是1.5.8版本的SpringBoot,在升级到2.0.*之后 ...

  8. 大数据技术之_11_HBase学习_02_HBase API 操作 + HBase 与 Hive 集成 + HBase 优化

    第6章 HBase API 操作6.1 环境准备6.2 HBase API6.2.1 判断表是否存在6.2.2 抽取获取 Configuration.Connection.Admin 对象的方法以及关 ...

  9. SpringBoot 的多数据源配置

    最近在项目开发中,需要为一个使用 MySQL 数据库的 SpringBoot 项目,新添加一个 PLSQL 数据库数据源,那么就需要进行 SpringBoot 的多数据源开发.代码很简单,下面是实现的 ...

随机推荐

  1. dubbo学习(八)dubbo项目搭建--消费者(服务消费者)

    PS:  项目架子以及工程间的maven依赖配置暂时省略,后续看情况可能会单独写一篇文章捋捋框架结构,先马克~ 配置和启动 1.pom文件引入dubbo和zookeeper的操作客户端(此步骤与生产者 ...

  2. python基本语法要注意哪些?本文详解!

    基本语法 第一个注释 print("hello,python") # 第二行注释 string_demo = "你好!" string_demo print ( ...

  3. xshell评估过期(已解决)

    登录英文版官网 https://www.netsarang.com/ 点击download  选择xshell 5 . 直接在页面中有红色*号的地方输入个人信息,licensetype 必须选 Hom ...

  4. 文件上传限制条件(JS、后缀、文件名、类型、截断)绕过及修复建议

    在现代互联网的Web应用程序中,上传文件是一 种常见的功能,因为它有助于提高业务效率,比如企业的OA系统,允许用户上传图片.视频.头像和许多其他类型的文件.然而向用户提供的功能越多,Web应用受到攻击 ...

  5. 虚拟机CentOS开机黑屏解决方案

    默认配置 错误: 1.直接就是黑屏,连杠杠都没有 2.centos系统关不掉 3.关闭vmware提示:虚拟机XXX繁忙 解决方案一: 1.以管理员身份运行cmd控制台程序 2.在cmd窗口中输入ne ...

  6. Python-序列切片原理和切片协议-[start:end:step] __getitem__

    切片原理图(顾头不顾尾的正则原理) # [0:1] 其实只取到C, 取e则 [-1:], 如果步长为负数则倒过来取,从第几个往回取 name = "ChuiXue" print(n ...

  7. 腾讯云Elasticsearch集群规划及性能优化实践

    ​一.引言 随着腾讯云 Elasticsearch 云产品功能越来越丰富,ES 用户越来越多,云上的集群规模也越来越大.我们在日常运维工作中也经常会遇到一些由于前期集群规划不到位,导致后期业务增长集群 ...

  8. 正睿十一A班模拟赛day1

    估分:25+0+60=85 实际:25+0+60=85 T1: 就只会25的暴力 分治,到一个区间[l,r],cnt[i]表示i这个颜色在区间内的出现次数,从两头同时扫描,扫描到第一个cnt[i]小于 ...

  9. 在Python中使用OpenCV(CV2)对图像进行边缘检测

    转载:https://blog.csdn.net/cumtb2002/article/details/107798767 Modules used: 使用的模块: For this, we will ...

  10. node-macaddress

    下载 node-macaddressnode-macaddress 检索Linux.OS X和Windows中的MAC地址. 关于MAC地址的一个常见误解是,每个主机只有一个MAC地址, 虽然一个主机 ...