创建springboot的starters项目,集成各种优秀springboot starter

Overview

一个基于springboot的项目快速集成脚手架

简介

spring-boot-starters是一个基于springboot的项目快速集成脚手架

其支持 Jdk 1.7+, SpringBoot 1.4.x 1.5.x 2.x.x。模块列表如下:

模块 说明
common-spring-boot-starter 公共模块
dynamic-datasource-spring-boot-starter 动态数据源模块
demo-project 用例模块
db-spring-boot-starter 集成druid数据源、集成mybatis-plus、动态数据源切换、pagehelper分页处理、Guava
log-spring-boot-starter 定义logback格式,统一log输出 、定义业务log通用json格式、sleuth日志埋点,链路跟踪
swagger-spring-boot-starter API文档
uaa-server-spring-boot-starter oauth2.0认证中心服务端
uaa-client-spring-boot-starter oauth2.0认证中心客户端
ribbon-spring-boot-starter ribbon客户端负载均衡
redis-spring-boot-starter redis快速集成
rabbitmq-spring-boot-starter rabbitmq消息中间间快速集成

1、动态数据源模块:dynamic-datasource-spring-boot-starter

特性

  1. 本模块继承于苞米豆的ynamic-datasource-spring-boot-starter模块
  2. 添加自定义p6spy SQL日志输出格式
  3. 支持 数据源分组 ,适用于多种场景 纯粹多库 读写分离 一主多从 混合模式。
  4. 支持数据库敏感配置信息 加密 ENC()。
  5. 支持每个数据库独立初始化表结构schema和数据库database。
  6. 支持 自定义注解 ,需继承DS(3.2.0+)。
  7. 提供对Druid,Mybatis-Plus,P6sy,Jndi的快速集成。
  8. 简化Druid和HikariCp配置,提供 全局参数配置 。配置一次,全局通用。
  9. 提供 自定义数据源来源 方案。
  10. 提供项目启动后 动态增加移除数据源 方案。
  11. 提供Mybatis环境下的 纯读写分离 方案。
  12. 提供使用 spel动态参数 解析数据源方案。内置spel,session,header,支持自定义。
  13. 支持 多层数据源嵌套切换 。(ServiceA >>> ServiceB >>> ServiceC)。
  14. 提供对shiro,sharding-jdbc,quartz等第三方库集成的方案,注意事项和示例。
  15. 提供 基于seata的分布式事务方案。 附:不支持原生spring事务。
  16. 提供 本地多数据源事务方案。 附:不支持原生spring事务。

约定

  1. 本框架只做 切换数据源 这件核心的事情,并不限制你的具体操作,切换了数据源可以做任何CRUD。
  2. 配置文件所有以下划线 _ 分割的数据源 首部 即为组的名称,相同组名称的数据源会放在一个组下。
  3. 切换数据源可以是组名,也可以是具体数据源名称。组名则切换时采用负载均衡算法切换。
  4. 默认的数据源名称为 master ,你可以通过 spring.datasource.dynamic.primary 修改。
  5. 方法上的注解优先于类上注解。
  6. 强烈建议只在service的类和方法上添加注解,不建议在mapper上添加注解。

使用方法

  1. 引入dynamic-datasource-spring-boot-starter。
<dependency>
  <groupId>com.zsx</groupId>
  <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
  <version>${version}</version>
</dependency>
  1. 配置数据源。
spring:
  datasource:
    dynamic:
      primary: master #设置默认的数据源或者数据源组,默认值即为master
      strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.
      datasource:
        master:
          url: jdbc:mysql://xx.xx.xx.xx:3306/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
        slave_1:
          url: jdbc:mysql://xx.xx.xx.xx:3307/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.jdbc.Driver
        slave_2:
          url: ENC(xxxxx) # 内置加密,使用请查看详细文档
          username: ENC(xxxxx)
          password: ENC(xxxxx)
          driver-class-name: com.mysql.jdbc.Driver
          schema: db/schema.sql # 配置则生效,自动初始化表结构
          data: db/data.sql # 配置则生效,自动初始化数据
          continue-on-error: true # 默认true,初始化失败是否继续
          separator: ";" # sql默认分号分隔符
          
       #......省略
       #以上会配置一个默认库master,一个组slave下有两个子库slave_1,slave_2
# 多主多从                      纯粹多库(记得设置primary)                   混合配置
spring:                               spring:                               spring:
  datasource:                           datasource:                           datasource:
    dynamic:                              dynamic:                              dynamic:
      datasource:                           datasource:                           datasource:
        master_1:                             mysql:                                master:
        master_2:                             oracle:                               slave_1:
        slave_1:                              sqlserver:                            slave_2:
        slave_2:                              postgresql:                           oracle_1:
        slave_3:                              h2:                                   oracle_2:
  1. 使用 @DS 切换数据源。

@DS 可以注解在方法上或类上,同时存在就近原则 方法上注解 优先于 类上注解

注解 结果
没有@DS 默认数据源
@DS("dsName") dsName可以为组名也可以为具体某个库的名称
@Service
@DS("slave")
public class UserServiceImpl implements UserService {

  @Autowired
  private JdbcTemplate jdbcTemplate;

  public List selectAll() {
    return  jdbcTemplate.queryForList("select * from user");
  }
  
  @Override
  @DS("slave_1")
  public List selectByCondition() {
    return  jdbcTemplate.queryForList("select * from user where age >10");
  }
}

You might also like...

Professional Java Developer Career Starter: Java Foundations Course Exercise Solutions

java-foundations-solutions Professional Java Developer Career Starter: Java Foundations Course Exercise Solutions The solutions are generally to be fo

Dec 28, 2022

A Spigot latest maven starter template.

NAME One sentence to describe your plugin. Introduction Describe your plugin clearly. Features Feature 1 Dependencies Commands /command Command functi

Jul 1, 2022

本项目基于springboot进行开发,实现了一系列的spring-boot-starter

项目简介 本项目基于springboot进行开发,实现了一系列的spring-boot-starter,可以作为开发中的工具包进行使用。 模块划分 common-spring-boot-starter:常用的基础类,比如用作消息流转的Msg以及一些工具类 monitor-spring-boot-st

Jan 24, 2022

Get or Throw Spring boot Starter will help you to hide handling if entity not found.

Get or Throw Spring boot Starter Get or Throw Spring boot Starter will help you to hide handling if entity not found. 1. Setup 2. Usage Library adds c

Feb 2, 2022

Best practice of monolithic spring application starter

Best practice of monolithic spring application starter

Best practice of monolithic spring application starter

Jul 19, 2022

Kafka-spring-boot-starter: encapsulated based on spring-kafka

Kafka-spring-boot-starter: encapsulated based on spring-kafka

Encapsulation based on spring-kafka not only supports native configuration, but also adds multi data source configuration.

Jan 9, 2023

starter project for react native cli setups, typescript included

starter project for react native cli setups, typescript included

A starter project with react native 0.68, @storybook/react-native 6.0 beta, storybook/addon-react-native-web getting started To get all the dependenci

Dec 21, 2022

React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀🚀🚀

React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀🚀🚀

React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀 🚀 🚀 Features React Native

Jan 3, 2023

Springboot starter security jwt

Springboot starter security jwt

Jul 19, 2022
Owner
justimaging
stay hungry stay foolish
justimaging
A springboot-starter that can achieve Intranet penetration. 一款可以实现内网穿透的springboot-starter。

qynat-springboot-starter 基于netty的内网穿透工具在springboot中的整合 protocol协议:protobuf 只需在application.properties中配置少量信息,实现零代码侵入的web项目内网穿透 项目的server端的源码在另一个多模块项目中,

whz11 65 Dec 12, 2022
Spring Boot starter module for gRPC framework.

Spring Boot starter module for gRPC framework.

Michael Zhang 2.8k Jan 4, 2023
Spring Boot starter module for gRPC framework.

Spring Boot starter module for gRPC framework.

Michael Zhang 1.8k Mar 17, 2021
Tuya 37 Dec 26, 2022
A React Native project starter with Typescript, a theme provider with hook to easy styling component, a folder architecture ready and some configs to keep a codebase clean.

React Native Boilerplate Folder structure : src ├── assets │   ├── audios │   ├── fonts │   ├── icons │   └── images ├── components │   ├── Layout.tsx

LazyRabbit 23 Sep 1, 2022
Spring Boot starter for JustAuth Plus.

Spring Boot starter for JustAuth Plus.

Fujie 5 Jun 23, 2022
基于 spring-boot-starter-log4j2:2.6.1 (log4j 2.14.1)

Log4j 2 CVE-2021-44228 测试样本应用 基于 spring-boot-starter-log4j2:2.6.1 (log4j 2.14.1) 可用接口 接口 请求方法 参数 vulnerable_request_get GET v=payload vulnerable_reque

Zhangzhe 3 Mar 23, 2022
An awesome Spring Boot Starter!

spring-boot-tony-starter An awesome Spring Boot Starter! Explore the docs » View Demo · Report Bug · Request Feature Table of Contents About The Proje

徐植君 11 Sep 13, 2022
Create your Java crypto trading bot in minutes. Our Spring boot starter takes care of exchange connections, accounts, orders, trades, and positions so you can focus on building your strategies.

Quick Start | Documentation | Discord | Twitter Create and run your java crypto trading bot in minutes Our Spring boot starter takes care of exchange

Cassandre 442 Jan 3, 2023
A springboot starter for retrofit, and supports many functional feature enhancements, greatly simplifying development

retrofit-spring-boot-starter English Document Retrofit是适用于Android和Java且类型安全的HTTP客户端,其最大的特性的是支持通过接口的方式发起HTTP请求。而spring-boot是使用最广泛的Java开发框架,但是Retrofit官方

Ke Technologies 1.4k Jan 5, 2023