一 环境
- 使用Spring Boot微服务
- hbase上部署了phoenix-server查询服务或者使用阿里云的hbase的phoenix查询服务
二 用mybatis访问phonix的正确姿势
其他配置与连mysql一样配置, 仅如下两个地方需要注意1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33package com.mafgwo.phoenixmybatisdemo.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.phoenix.queryserver.client.Driver;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* hbase phoenix 扫描配置
*
* @author mafgwo
* @since 2019/12/19
*/
"com.mafgwo.phoenixmybatisdemo.mapper") (basePackages =
public class PhoenixForMybatisConfiguration {
private DataSourceProperties dataSourceProperties;
public DataSource phoenixDataSource() {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(Driver.class.getName());
druidDataSource.setUrl(dataSourceProperties.getUrl());
return druidDataSource;
}
}
1 | spring: |