saas-datasource-spring-boot-starter

spring boot starter for Software-as-a-Service datasource base on mybatis-plus(https://github.com/baomidou/mybatis-plus)

Лицензия

Лицензия

Категории

Категории

Spring Boot Контейнер Микросервисы Данные
Группа

Группа

com.github.kuhn-he
Идентификатор

Идентификатор

saas-datasource-spring-boot-starter
Последняя версия

Последняя версия

3.0.6.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

saas-datasource-spring-boot-starter
spring boot starter for Software-as-a-Service datasource base on mybatis-plus(https://github.com/baomidou/mybatis-plus)
Ссылка на сайт

Ссылка на сайт

https://github.com/kuhn-he/saas-datasource-spring-boot-starter
Система контроля версий

Система контроля версий

https://github.com/kuhn-he/saas-datasource-spring-boot-starter

Скачать saas-datasource-spring-boot-starter

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.kuhn-he/saas-datasource-spring-boot-starter/ -->
<dependency>
    <groupId>com.github.kuhn-he</groupId>
    <artifactId>saas-datasource-spring-boot-starter</artifactId>
    <version>3.0.6.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.kuhn-he/saas-datasource-spring-boot-starter/
implementation 'com.github.kuhn-he:saas-datasource-spring-boot-starter:3.0.6.3'
// https://jarcasting.com/artifacts/com.github.kuhn-he/saas-datasource-spring-boot-starter/
implementation ("com.github.kuhn-he:saas-datasource-spring-boot-starter:3.0.6.3")
'com.github.kuhn-he:saas-datasource-spring-boot-starter:jar:3.0.6.3'
<dependency org="com.github.kuhn-he" name="saas-datasource-spring-boot-starter" rev="3.0.6.3">
  <artifact name="saas-datasource-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.kuhn-he', module='saas-datasource-spring-boot-starter', version='3.0.6.3')
)
libraryDependencies += "com.github.kuhn-he" % "saas-datasource-spring-boot-starter" % "3.0.6.3"
[com.github.kuhn-he/saas-datasource-spring-boot-starter "3.0.6.3"]

Зависимости

compile (5)

Идентификатор библиотеки Тип Версия
com.baomidou : mybatis-plus-boot-starter jar 3.0.6
com.baomidou : dynamic-datasource-spring-boot-starter jar 2.4.2
com.alibaba : druid-spring-boot-starter jar 1.1.10
org.projectlombok : lombok jar 1.18.0
org.apache.commons : commons-lang3 jar 3.5

provided (4)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-web jar 2.0.3.RELEASE
com.fasterxml.jackson.core : jackson-annotations jar 2.9.5
com.fasterxml.jackson.core : jackson-core jar 2.9.5
com.fasterxml.jackson.core : jackson-databind jar 2.9.5

runtime (1)

Идентификатор библиотеки Тип Версия
com.h2database : h2 jar 1.4.197

Модули Проекта

Данный проект не имеет модулей.

saas-datasource-spring-boot-starter

spring boot starter for Software-as-a-Service datasource base on mybatis-plus(https://github.com/baomidou/mybatis-plus)

How to publish saas spring boot starter

  • add Dependencies:
<dependency>
    <groupId>com.github.kuhn-he</groupId>
    <artifactId>saas-datasource-spring-boot-starter</artifactId>
    <version>3.0.6.3</version>
</dependency>
  • add saas datasource configuration in application.properties, demo:
spring.autoconfigure.exclude=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
spring.datasource.dynamic.primary=mysql
spring.datasource.dynamic.datasource.mysql.url = jdbc:mysql://127.0.0.1:3306/saas?characterEncoding=utf-8
spring.datasource.dynamic.datasource.mysql.username = root
spring.datasource.dynamic.datasource.mysql.password = root
spring.datasource.dynamic.datasource.mysql.driver-class-name = com.mysql.jdbc.Driver

How to switch business datasources

  • custom dynamic datasource provider for switch business datasources, demo:
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.github.kuhn_he.saas.ds.DynamicDataSourcePlusCreator;
import com.github.kuhn_he.saas.ds.DynamicDataSourcePlusProvider;

@Component
public class SampleDynamicDataSourceProvider implements DynamicDataSourcePlusProvider {

	@Autowired
	private DynamicDataSourcePlusCreator dynamicDataSourcePlusCreator;
	
	@Override
	public DataSource createDataSource(String dsKey) {
		//...
		DataSourceProperty dataSourceProperty=new DataSourceProperty();
		//...
		return dynamicDataSourcePlusCreator.createDruidDataSource(dataSourceProperty);
	}
}
  • then add @EnableDynamicRouteDataSource on Spring Boot Application, indicates that saas is enabled.
import com.github.kuhn_he.saas.ds.annotation.EnableDynamicRouteDataSource;

@SpringBootApplication
@EnableDynamicRouteDataSource
public class ApplicationBootstrap {
 //...
}
  • code your database Mapper, add @SAAS(import com.github.kuhn_he.mapper.SAAS) on your Mapper interface(non-annotation @SAAS is default datasource which is saas datasouce configuration in application.properties).
import com.github.kuhn_he.saas.ds.annotation.SAAS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

@SAAS //default is x-datasource-key which datasource key put in header or session. 
@Mapper
public interface SampleMapper extends BaseMapper<TSample>{
 //...
}

Reference

sample see: saas-springboot-sample

Версии библиотеки

Версия
3.0.6.3
3.0.6.2
mybatis-plus-3.0.6.1