1. pom 文件
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tianjishuju.platform.server</groupId>
<artifactId>hbase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hbase</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- lombok 插件可以去掉 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.phoenix/phoenix-core -->
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.14.1-HBase-1.4</version>
</dependency>
<!-- habse伪分布式安装,这里需要加上hadoop-common, 单机安装可以去掉 -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.8.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2. yml 配置文件
server:
port: 9000
spring:
datasource:
url: jdbc:phoenix:localhost:2181
driver-class-name: org.apache.phoenix.jdbc.PhoenixDriver
data-password:
data-username:
type: com.tianjishuju.platform.server.hbase.utils.PhoenixNoPoolingDatasource #自定义数据类型
3. 自定义类class:
package com.tianjishuju.platform.server.hbase.utils;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import java.sql.Driver;
import java.util.Properties;
public class PhoenixNoPoolingDatasource extends SimpleDriverDataSource {
public PhoenixNoPoolingDatasource() {
}
public PhoenixNoPoolingDatasource(Driver driver, String url) {
super(driver, url);
}
public PhoenixNoPoolingDatasource(Driver driver, String url, String username, String password) {
super(driver, url, username, password);
}
public PhoenixNoPoolingDatasource(Driver driver, String url, Properties conProps) {
super(driver, url, conProps);
}
public void setDriverClassName(String driverClassName) {
try {
Class<?> driverClass = this.getClass().getClassLoader().loadClass(driverClassName);
setDriverClass((Class<? extends Driver>) driverClass);
} catch (Exception e) {
throw new RuntimeException("Failed to load class of driverClassName " + driverClassName, e);
}
}
}
备注:
这里只做关键点说明,其余步骤按类似 spring 整合 mybatis + mysql 方式进行