dynamic-datasource+shardingsphere-jdbc realizes sub-database and sub-table

Project background On the basis of spring boot and dynamic-datasource realizing the separation of reading and writing of the database, the function of sub-database and table is added. 1. Framework version 1. Key technology stack versions <properties> <java.version>8</java.version> <snakeyaml.version>1.33</snakeyaml.version> </properties> <dependencies> <!– druid connection pool –> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.20</version> </dependency> <!–dynamic-datasource–> <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> […]

MyBatis-Plus and Druid combine with Dynamic-datasource to realize multi-data source operation database

MyBatis-Plus official website: https://baomidou.com/ MyBatis-Plus official documentation: https://baomidou.com/pages/24112f/ dynamic-datasource documentation (paid): https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611 Create database Here I created two databases: test1 and test2, and created data tables with the same structure User respectively. Of course, you can also Create data tables with different structures according to the actual situation: ——————————- –User table structure —————————- CREATE TABLE […]

Use dynamic-datasource to complete multiple data source operations

This operation is to insert the data from Dameng database into the MySQL database. Preparation Create a Spring Boot project Add dependencies Configure data source properties POM file <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.32</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>3.5.2</version> </dependency> <!– Add dm8 jdbc jar package dependency –> <dependency> <groupId>com.dm</groupId> <artifactId>DmJdbcDriver</artifactId> <version>1.8.0</version> […]

MyBatis-Plus multi-data source dynamic-datasource solves the problem of multi-data source Redis Key duplication

Article directory Preface 1. Redis Key solution: 2. Redis Key adds data source identification: 2.1 Customize the serialization of redis key: 2.2 Add serialization of redis key: Summarize Foreword When using dynamic-datasource, multiple tenants share a system, but the cache resources set by each tenant must be isolated, otherwise it will cause chaos in the […]

springboot combines baomidou dynamic-datasource component to implement multiple data sources

When the amount of system data is too large, system performance problems gradually surface. Using the master-slave mode is a better choice. That is, the business is executed in the main database, and queries that do not affect the business are considered to go to the slave database. At this time, the program requires dynamic […]

sprintboot + mybatis plus + dynamic-datasource multiple data switching and ensure transaction consistency of multiple data sources

Foreword: This project is a single project and does not involve distributed transactions. The requirements are relatively straightforward. It is to query the data of two databases at the same time in one request method and insert data into the two databases. Ensure transaction consistency 1. Multiple data source dependencies <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>3.3.5</version> </dependency> […]

[mybatis-plus] Multiple data source switching [dynamic-datasource] Manually switch data sources

Springboot + mybatis-plus + dynamic-datasource + Druid manually switch data sources Article directory Springboot + mybatis-plus + dynamic-datasource + Druid manually switch data sources 0.Preface 1. Brief analysis of core classes of multiple data sources 1. 1. DynamicDataSourceContextHolder switches the data source core class 1.2. DynamicRoutingDataSource 2. Based on the understanding of core classes, we […]

springboot integrates mybatis-plus+dynamic-datasource to achieve separation of reading and writing

Step one, guide package The data source uses druid. The druid and mybatis-plus versions here are not the latest, so you can choose them yourself. <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>2.1.9</version> </dependency> Step 2, write configuration The SqlServer used in the database here can be modified by […]

Springboot+dynamic-datasource+Druid database configuration encryption

Springboot + mybatis-plus + dynamic-datasource + Druid database configuration encryption Article directory 0.Preface 1. Dynamically add and remove data sources 2.Basic introduction 3. Example of usage steps Simple way, use default encryption 1. Use the following tool to output the encrypted password 1. Configure the above encrypted password into the configuration file If the default […]

dynamic-datasource-spring-boot-starter for multiple data sources

demo structure java service BasicTestServiceImpl BasicTestServiceImpl resources mapper BotBasicTestMapper.xml BotKmsTestMapper.xml application.properties POM java service BasicTestServiceImpl @DS(value = CommonConstant.SMARTXMABASIC) @Service public class BasicTestServiceImpl implements BasicTestService {<!– –> @Autowired private BasicTestMapper basicTestMapper; @Override public List<Map<String, Object>> qureyEntityInfo() {<!– –> return basicTestMapper.selectInfo(); } } BasicTestServiceImpl @DS(value = CommonConstant.SMARTXMAKMS) @Service public class KmsEntityServiceImpl implements KmsEntityService {<!– –> @Autowired private […]