Skip to content

flyingglass/phoenix-mybatis-plus-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phoenix-mybatis-plus-starter

简介

该项目主要利用SpringBoot的自动化配置特性来实现快速的将Mybatis-Plus + Phoenix引入Springboot项目中,简化原生Mybatis-Plus整合Phoenix使用。

欢迎使用和star支持,如使用中碰到问题,可以提出Issue,我会尽力完善该Starter

版本基础

  • Mybatis-Plus: 3.2.0
  • Spring-Boot: 2.2.2.RELEASE

Quick-Start

轻松引入SpringBoot工程中,需要如下步骤:

  • pom.xml中引入依赖:
<dependency>
    <groupId>com.github.flyingglass</groupId>
    <artifactId>phoenix-mybatis-plus-starter</artifactId>
    <version>1.0.0</version>
</dependency>
  • 在应用主类中增加@MapperScan(basePackages = "com.xxx.mapper")注解,用于扫描MapperInterface,并且排除DruidDataSourceAutoConfigure
@MapperScan(basePackages = "com.xxx.mapper")
@SpringBootApplication(
        exclude = DruidDataSourceAutoConfigure.class
)
public class Bootstrap {

    public static void main(String[] args) {
        SpringApplication.run(Bootstrap.class, args);
    }

}
  • 配置application.yml

配置phoenix数据源,已针对phoenix-core进行shaded repackage解决Springboot兼容问题

  • 配置pom.xml
<dependency>
    <groupId>com.github.flyingglass</groupId>
    <artifactId>phoenix-core-shaded</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.phoenix</groupId>
            <artifactId>phoenix-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.github.flyingglass</groupId>
    <artifactId>hbase-client-shaded</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • 配置application.yml
spring:
  datasource:
    dynamic:
      primary: master
      datasource:
        master:
          username:
          password:
          url: jdbc:phoenix:znode01,znode02,znode03:2181
          driver-class-name: org.apache.phoenix.jdbc.PhoenixDriver
          druid:
            filters: stat
            connection-properties:
              schema: "\"TEST\""

自定义特性

  • 通过Mybatis-plusSqlInjector注入PhoenixUpsertupsert方法适应phoenix插入方法
  • 自定义IPhoenixService,用户的Service继承自PhoenixServiceImpl即可复用Mybatis-plusServiceImpl<M, T>所有方法
  • 关于PhoenixHBase的版本兼容问题,对于包冲突,需要额外shaded repackage,参考:https://github.com/FlyingGlass/hbase-phoenix-shaded