Skip to content
Back to search

dynamic-datasource

dynamic datasource for springboot 多数据源 动态数据源 主从分离 读写分离 分布式事务

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/baomidou--dynamic-datasource/badge.svg)](/listings/baomidou--dynamic-datasource)

HTML

<a href="/listings/baomidou--dynamic-datasource"><img src="/api/listings/baomidou--dynamic-datasource/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

**1 · Add the dependency** (shown for `4.5.0`; replace with the [latest release](https://github.com/baomidou/dynamic-datasource/releases)).

<details> <summary><b>Maven</b></summary>

<!-- Spring Boot 2.x (and 1.5.x) -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
    <version>4.5.0</version>
</dependency>

<!-- Spring Boot 3.x -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
    <version>4.5.0</version>
</dependency>

<!-- Spring Boot 4.x -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot4-starter</artifactId>
    <version>4.5.0</version>
</dependency>

</details>

<details> <summary><b>Gradle</b></summary>

// choose exactly one, matching your Spring Boot line
implementation 'com.baomidou:dynamic-datasource-spring-boot-starter:4.5.0'
implementation 'com.baomidou:dynamic-datasource-spring-boot3-starter:4.5.0'
implementation 'com.baomidou:dynamic-datasource-spring-boot4-starter:4.5.0'

</details>

**2 · Declare your datasources.** Everything after the `datasource:` key is a datasource name; the part before the first `_` becomes its group.

spring:
  datasource:
    dynamic:
      enabled: true              # master switch, default true
      primary: master            # default datasource or group, default "master"
      strict: false              # true = throw when the key does not resolve
      grace-destroy: false       # true = wait up to 10s for active connections on shutdown
      datasource:
        master:
          url: jdbc:mysql://xx.xx.xx.xx:3306/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.cj.jdbc.Driver   # optional since 3.2.0 (SPI based)
        slave_1:
          url: jdbc:mysql://xx.xx.xx.xx:3307/dynamic
          username: root
          password: 123456
          driver-class-name: com.mysql.cj.jdbc.Driver
        slave_2:
          url: ENC(xxxxx)        # built-in encryption, see the documentation
          username: ENC(xxxxx)
          password: ENC(xxxxx)
          driver-class-name: com.mysql.cj.jdbc.Driver

The snippet above yields one `master` datasource plus a `slave` group containing `slave_1` and `slave_2`. Other shapes are equally declarative:

# one master, many slaves        # pure multi-database          # mixed
master:                            mysql:                        master:
slave_1:                           oracle:                       slave_1:
slave_2:                           sqlserver:                    slave_2:
                                   h2:                           oracle_1:
                                                                 oracle_2:

**3 · Route with `@DS`.** Applicable to methods and types; when both are present the method wins.

@Service
@DS("slave")
public class UserServiceImpl implements UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @DS("master") // pinned to the master datasource
    public List<Map<String, Object>> selectAll() {
        return jdbcTemplate.queryForList("select * from user");
    }

    @DS("slave_1") // pinned to one concrete datasource
    public List<Map<String, Object>> selectByCondition() {
        return jdbcTemplate.queryForList("select * from user where age > 10");
    }
}

| Annotation | Resolved datasource | | :--- | :--- | | none | the `primary` datasource | | `@DS("slave")` | the `slave` **group**, balanced across its members | | `@DS("slave_1")` | the `slave_1` **datasource** | | `@Master` / `@Slave` | shortcuts shipped for the `master` / `slave` names |

Any annotation that is itself meta-annotated with `@DS` works as a datasource switch — that is exactly how `@Master` and `@Slave` are shipped, and it lets you define a domain-specific one such as

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 406 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <p align="center">
  2. <img src="https://images.gitee.com/uploads/images/2019/0626/231046_f44892b9_709883.png" alt="dynamic-datasource" width="150" />
  3. </p>
  4. <h1 align="center">Dynamic Datasource</h1>
  5. <p align="center">
  6. <strong>Multi-datasource routing for Spring Boot — switch with a single annotation.</strong><br/>
  7. Read/write splitting · one master / many slaves · polyglot databases · dynamic routing · distributed &amp; local transactions
  8. </p>
  9. <p align="center">
  10. <b>English</b> · <a href="./README_zh_CN.md">简体中文</a>
  11. </p>
  12. <p align="center">
  13. <a href="https://github.com/baomidou/dynamic-datasource/actions/workflows/ci.yml">
  14. <img src="https://github.com/baomidou/dynamic-datasource/actions/workflows/ci.yml/badge.svg" alt="CI" />
  15. </a>
  16. <a href="https://github.com/baomidou/dynamic-datasource/releases">
  17. <img src="https://img.shields.io/github/v/release/baomidou/dynamic-datasource?label=release&color=blue" alt="Release" />
  18. </a>
  19. <a href="https://central.sonatype.com/artifact/com.baomidou/dynamic-datasource-spring-boot-starter">
  20. <img src="https://img.shields.io/maven-central/v/com.baomidou/dynamic-datasource-spring-boot-starter.svg?label=boot2%20starter&color=green" alt="Boot 2 starter" />
  21. </a>
  22. <a href="https://central.sonatype.com/artifact/com.baomidou/dynamic-datasource-spring-boot3-starter">
  23. <img src="https://img.shields.io/maven-central/v/com.baomidou/dynamic-datasource-spring-boot3-starter.svg?label=boot3%20starter&color=green" alt="Boot 3 starter" />
  24. </a>
  25. <a href="https://central.sonatype.com/artifact/com.baomidou/dynamic-datasource-spring-boot4-starter">
  26. <img src="https://img.shields.io/maven-central/v/com.baomidou/dynamic-datasource-spring-boot4-starter.svg?label=boot4%20starter&color=green" alt="Boot 4 starter" />
  27. </a>
  28. <a href="https://www.apache.org/licenses/LICENSE-2.0.html">
  29. <img src="https://img.shields.io/badge/license-Apache--2.0-brightgreen.svg" alt="License" />
  30. </a>
  31. <img src="https://img.shields.io/badge/JDK-8%2B%20(Boot3%2F4%2017%2B)-orange.svg" alt="JDK" />
  32. <img src="https://img.shields.io/badge/Spring%20Boot-1.5%20~%204.x-99ccff.svg" alt="Spring Boot" />
  33. <img src="https://img.shields.io/badge/GraalVM%20Native-CI%20tested-4299f1.svg" alt="GraalVM Native Image" />
  34. <a href="https://scorecard.dev/viewer/?uri=github.com/baomidou/dynamic-datasource">
  35. <img src="https://api.securityscorecards.dev/projects/github.com/baomidou/dynamic-datasource/badge" alt="OpenSSF Scorecard" />
  36. </a>
  37. <a href="https://baomidou.github.io/dynamic-datasource/">
  38. <img src="https://img.shields.io/badge/API%20docs-Javadoc-4c9b3c.svg" alt="Javadoc" />
  39. </a>
  40. </p>
  41. ---
  42. ## Table of Contents
  43. - [Why this project](#why-this-project)
  44. - [Highlights](#highlights)
  45. - [Compatibility](#compatibility)
  46. - [Quick start](#quick-start)
  47. - [Naming conventions & routing rules](#naming-conventions--routing-rules)
  48. - [Transactions](#transactions)
  49. - [Dynamic datasource keys](#dynamic-datasource-keys)
  50. - [Runtime management](#runtime-management)
  51. - [Ecosystem integrations](#ecosystem-integrations)
  52. - [Module layout](#module-layout)
  53. - [Documentation](#documentation)
  54. - [Contributing, Security and License](#contributing-security-and-license)
  55. ---
  56. ## Why this project
  57. Adding a second database to a Spring Boot application usually means hand-writing a second
  58. `DataSource` bean, a second `TransactionManager`, a second set of MyBatis/JPA wiring — and then
  59. still not knowing how to route a call to one of them.
  60. **dynamic-datasource** replaces all of that with a single starter: declare your datasources in
  61. YAML, annotate a class or method with `@DS("slave")`, and the framework resolves the connection at
  62. invocation time, restores it when the call returns, and nests correctly across service layers. It
  63. has been maintained since 2018, ships artifacts for three Spring Boot generations, and is validated
  64. by CI on a JDK 17/21/25/27 matrix (the Boot 2 line is compiled and tested through a JDK 8 toolchain)
  65. plus GraalVM Native Image.
  66. > It does exactly one thing — **choosing which `DataSource` a call runs against** — and deliberately
  67. > does not constrain what you do afterwards. Any CRUD, any ORM, any transaction strategy.
  68. > The full reference — every configuration key, connection pool and integration recipe — lives on
  69. > [doc.xiuceyun.cn](https://doc.xiuceyun.cn) (Chinese); the [wiki](https://github.com/baomidou/dynamic-datasource/wiki/Home-English)
  70. > is taking over page by page. See [Documentation](#documentation).
  71. ## Highlights
  72. | Area | What you get |
  73. | --- | --- |
  74. | **Grouping** | Pure multi-DB, read/write splitting, one-master-many-slaves, or a mix of all three, expressed by naming alone. |
  75. | **Routing** | `@DS` on method / class / interface / abstract class, nearest declaration wins; group names resolve through a load-balanced or random strategy. |
  76. | **Transactions** | Local multi-datasource transactions via `@DSTransactional` (7 propagation levels), plus Seata `AT` / `XA` and Atomikos XA for truly distributed commits. |
  77. | **Security** | `ENC(...)` encrypted credentials out of the box, customisable algorithm and public key; SpEL type access restricted by default. |
  78. | **Lifecycle** | Start with zero datasources, lazy-initialise on first use, add/remove datasources at runtime, graceful shutdown that waits for in-flight connections. |
  79. | **Extensibility** | Custom annotations that meta-annotate `@DS`, custom `DsProcessor` chain, custom `DataSourceProvider`, pluggable `DataSourceCreator`. |
  80. | **Connectivity** | Curated integration for Druid, HikariCP, BeeCP, DBCP2, C3P0, Oracle UCP, unpooled basic datasources and JNDI lookups. |
  81. | **Native** | GraalVM reachability metadata published as an artifact; `nativeTest` gates every commit in CI. |
  82. ## Compatibility
  83. Pick the starter that matches your Spring Boot line (the maintenance status of each line is defined in [SUPPORT.md](./SUPPORT.md)):
  84. | Spring Boot | JDK | Starter artifact | Available since |
  85. | :---: | :---: | :--- | :---: |
  86. | 1.5.x ~ 2.x.x | JDK 8+ | `dynamic-datasource-spring-boot-starter` | 1.0.0 |
  87. | 3.x.x | JDK 17+ | `dynamic-datasource-spring-boot3-starter` | 4.0.0 |
  88. | 4.x.x | JDK 17+ | `dynamic-datasource-spring-boot4-starter` | 4.5.0 |
  89. > Connection pools (Druid / HikariCP / …) and JDBC drivers are **not** bundled. Bring your own and
  90. > keep the versions aligned with your Spring Boot line — this is what keeps the starter lightweight
  91. > and avoids the classpath conflicts that a shaded starter would cause.
  92. ## Quick start
  93. **1 · Add the dependency** (shown for `4.5.0`; replace with the [latest release](https://github.com/baomidou/dynamic-datasource/releases)).
  94. <details>
  95. <summary><b>Maven</b></summary>
  96. ```xml
  97. <!-- Spring Boot 2.x (and 1.5.x) -->
  98. <dependency>
  99. <groupId>com.baomidou</groupId>
  100. <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
  101. <version>4.5.0</version>
  102. </dependency>
  103. <!-- Spring Boot 3.x -->
  104. <dependency>
  105. <groupId>com.baomidou</groupId>
  106. <artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
  107. <version>4.5.0</version>
  108. </dependency>
  109. <!-- Spring Boot 4.x -->
  110. <dependency>
  111. <groupId>com.baomidou</groupId>
  112. <artifactId>dynamic-datasource-spring-boot4-starter</artifactId>
  113. <version>4.5.0</version>
  114. </dependency>
  115. ```
  116. </details>
  117. <details>
  118. <summary><b>Gradle</b></summary>
  119. ```groovy
  120. // choose exactly one, matching your Spring Boot line
  121. implementation 'com.baomidou:dynamic-datasource-spring-boot-starter:4.5.0'
  122. implementation 'com.baomidou:dynamic-datasource-spring-boot3-starter:4.5.0'
  123. implementation 'com.baomidou:dynamic-datasource-spring-boot4-starter:4.5.0'
  124. ```
  125. </details>
  126. **2 · Declare your datasources.** Everything after the `datasource:` key is a datasource name; the
  127. part before the first `_` becomes its group.
  128. ```yaml
  129. spring:
  130. datasource:
  131. dynamic:
  132. enabled: true # master switch, default true
  133. primary: master # default datasource or group, default "master"
  134. strict: false # true = throw when the key does not resolve
  135. grace-destroy: false # true = wait up to 10s for active connections on shutdown
  136. datasource:
  137. master:
  138. url: jdbc:mysql://xx.xx.xx.xx:3306/dynamic
  139. username: root
  140. password: 123456
  141. driver-class-name: com.mysql.cj.jdbc.Driver # optional since 3.2.0 (SPI based)
  142. slave_1:
  143. url: jdbc:mysql://xx.xx.xx.xx:3307/dynamic
  144. username: root
  145. password: 123456
  146. driver-class-name: com.mysql.cj.jdbc.Driver
  147. slave_2:
  148. url: ENC(xxxxx) # built-in encryption, see the documentation
  149. username: ENC(xxxxx)
  150. password: ENC(xxxxx)
  151. driver-class-name: com.mysql.cj.jdbc.Driver
  152. ```
  153. The snippet above yields one `master` datasource plus a `slave` group containing `slave_1` and
  154. `slave_2`. Other shapes are equally declarative:
  155. ```yaml
  156. # one master, many slaves # pure multi-database # mixed
  157. master: mysql: master:
  158. slave_1: oracle: slave_1:
  159. slave_2: sqlserver: slave_2:
  160. h2: oracle_1:
  161. oracle_2:
  162. ```
  163. **3 · Route with `@DS`.** Applicable to methods and types; when both are present the method wins.
  164. ```java
  165. @Service
  166. @DS("slave")
  167. public class UserServiceImpl implements UserService {
  168. @Autowired
  169. private JdbcTemplate jdbcTemplate;
  170. @DS("master") // pinned to the master datasource
  171. public List<Map<String, Object>> selectAll() {
  172. return jdbcTemplate.queryForList("select * from user");
  173. }
  174. @DS("slave_1") // pinned to one concrete datasource
  175. public List<Map<String, Object>> selectByCondition() {
  176. return jdbcTemplate.queryForList("select * from user where age > 10");
  177. }
  178. }
  179. ```
  180. | Annotation | Resolved datasource |
  181. | :--- | :--- |
  182. | none | the `primary` datasource |
  183. | `@DS("slave")` | the `slave` **group**, balanced across its members |
  184. | `@DS("slave_1")` | the `slave_1` **datasource** |
  185. | `@Master` / `@Slave` | shortcuts shipped for the `master` / `slave` names |
  186. Any annotation that is itself meta-annotated with `@DS` works as a datasource switch — that is exactly
  187. how `@Master` and `@Slave` are shipped, and it lets you define a domain-specific one such as
  188. `@OracleDs` declared as `@DS("oracle")`.
  189. ## Naming conventions & routing rules
  190. 1. All datasource configuration keys are read under `spring.datasource.dynamic.datasource`.
  191. 2. The segment before the first `_` is the **group name**; names sharing a group are pooled into one `GroupDataSource`.
  192. 3. You may switch to a group name or to a concrete datasource name; groups are resolved by `strategy` (load balance by default, `RandomDynamicDataSourceStrategy` optional).
  193. 4. The default datasource is `master`, overridable via `spring.datasource.dynamic.primary`.
  194. 5. Resolution priority, nearest wins: **programmatic push (`DynamicDataSourceContextHolder.push`) > method annotation > class annotation**, and `@DS` inherited from interfaces or abstract classes is honoured.
  195. 6. The datasource stack is pushed and popped per invocation, so `ServiceA >>> ServiceB >>> ServiceC` nesting across different datasources behaves as expected.
  196. ## Transactions
  197. **Local, no external coordinator** — `@DSTransactional` binds one connection per participating
  198. datasource under a transaction id, then commits or rolls all of them back together at the boundary;
  199. nested transactions are handled through save points. A failure in the last datasource undoes what the
  200. earlier ones already wrote.
  201. ```java
  202. @DSTransactional(propagation = DsPropagation.REQUIRED, rollbackFor = Exception.class)
  203. @DS("master")
  204. public void transfer() {
  205. userMapper.debit(); // master
  206. logMapper.write(); // log_1, switched inside the call chain via @DS
  207. }
  208. ```
  209. Propagation levels: `REQUIRED` (default), `REQUIRES_NEW`, `NESTED`, `SUPPORTS`, `NOT_SUPPORTED`, `MANDATORY`, `NEVER`.
  210. Transaction events can be observed with `@DsTxEventListener` (commit / rollback / after-completion), the
  211. multi-datasource counterpart of Spring's `@TransactionalEventListener`.
  212. **Distributed** — two first-class options:
  213. ```yaml
  214. # 1) Seata: proxy each datasource for a global commit
  215. spring:
  216. datasource:
  217. dynamic:
  218. seata: true # wrap datasources for Seata
  219. seata-mode: AT # AT (default) or XA
  220. ```
  221. ```yaml
  222. # 2) Atomikos XA: point driver-class-name at an XA datasource
  223. spring:
  224. datasource:
  225. dynamic:
  226. atomikos: # global pool tuning; per-datasource overrides apply on top
  227. max-pool-size: 10
  228. datasource:
  229. master:
  230. driver-class-name: com.mysql.cj.jdbc.MysqlXADataSource
  231. url: jdbc:mysql://xx.xx.xx.xx:3306/dynamic
  232. ```
  233. Supported XA resources: MySQL (5.x and 8+), Oracle, PostgreSQL, H2; on the MyBatis side pair them with
  234. `AtomikosTransactionFactory`.
  235. ## Dynamic datasource keys
  236. The `@DS` value does not have to be a literal. The built-in `DsProcessor` chain resolves it per
  237. request, and you can prepend your own processor:
  238. ```java
  239. @DS("#header.ds") // read the datasource key from an HTTP header
  240. @DS("#session.dsName") // ... or from the HTTP session
  241. @DS("#user.level") // SpEL against the method arguments
  242. @DS("@dsLocator.for(#id)") // SpEL with a bean reference
  243. ```
  244. > SpEL type references (`T(java.lang.Runtime)`) and constructor expressions are **disabled by
  245. > default** to block expression injection. Re-enable them only when genuinely required, via
  246. > `spring.datasource.dynamic.aop.allowed-spel-type-access: true`.
  247. Related AOP knobs: `aop.enabled`, `aop.order` (default `HIGHEST_PRECEDENCE`), `aop.allowed-public-only`.
  248. ## Runtime management
  249. ```java
  250. @Autowired
  251. private DynamicRoutingDataSource routingDataSource;
  252. @Autowired
  253. private DefaultDataSourceCreator dataSourceCreator;
  254. public void openTenant(String tenantId) {
  255. DataSourceProperty property = new DataSourceProperty();
  256. property.setPoolName("tenant_" + tenantId);
  257. property.setUrl("jdbc:mysql://db.internal:3306/tenant_" + tenantId);
  258. property.setUsername("app");
  259. property.setPassword("secret");
  260. // the property goes through the creator chain and becomes a real, initialised pool
  261. routingDataSource.addDataSource(property.getPoolName(), dataSourceCreator.createDataSource(property));
  262. }
  263. public void closeTenant(String tenantId) {
  264. routingDataSource.removeDataSource("tenant_" + tenantId); // destroyed, gracefully if configured
  265. }
  266. ```
  267. - `lazy: true` — a datasource is created on first access instead of at startup.
  268. - Starting with **no** datasource is supported; `AbstractJdbcDataSourceProvider` lets you load the
  269. catalogue itself from a bootstrap database.
  270. - Per-datasource initialisation scripts (`init.schema` / `init.data`), each with its own separator and
  271. error policy, so a group of heterogeneous databases can bootstrap independently.
  272. - `grace-destroy: true` — on shutdown, wait (at most 10s) for active connections before forcing close.
  273. - `ENC(...)` credentials with a global or per-datasource `public-key`, and `EncDataSourceInitEvent`
  274. as the hook for your own algorithm (AES, SM4, KMS…).
  275. - `p6spy: true` wraps datasources for SQL logging; `seata: false` opts a single datasource out of proxying.
  276. ## Ecosystem integrations
  277. - **MyBatis / MyBatis-Plus** — usable as a plain `DataSource`; `MasterSlaveAutoRoutingPlugin` gives
  278. pure read/write splitting with no annotation at all (`SELECT` → `slave`, everything else → `master`).
  279. - **Quartz** — hand the scheduler the dynamic `DataSource`; the documented recipe covers the JDBC job store.
  280. - **ShardingSphere / ShardingJDBC, P6spy, JNDI** — integration recipes are on the documentation site;
  281. they are being migrated into the wiki step by step.
  282. - **GraalVM Native Image** — reachability metadata for this project, Druid and HikariCP ships in
  283. `dynamic-datasource-native-metadata`; starter users pick it up through the native metadata repository.
  284. ## Module layout
  285. | Module | Responsibility |
  286. | --- | --- |
  287. | `dynamic-datasource-creator` | Datasource creation: pool adapters (Druid/HikariCP/BeeCP/DBCP2/C3P0/Oracle UCP/basic), XA resources, crypto helpers |
  288. | `dynamic-datasource-spring` | Core: `DynamicRoutingDataSource`, group/item datasources, `@DS` AOP, holder stack, transaction engine, strategies, plugins |
  289. | `dynamic-datasource-spring-boot-common` | Shared `DynamicDataSourceProperties` and auto-configuration building blocks |
  290. | `dynamic-datasource-spring-boot-starter` | Spring Boot 1.5.x ~ 2.x.x (`javax.*`) entry point |
  291. | `dynamic-datasource-spring-boot3-starter` | Spring Boot 3.x (`jakarta.*`) entry point |
  292. | `dynamic-datasource-spring-boot4-starter` | Spring Boot 4.x entry point |
  293. | `dynamic-datasource-native-metadata` | GraalVM reachability metadata shipped as an artifact |
  294. | `dynamic-datasource-test-common` | Shared test fixtures, not published |
  295. ## Documentation
  296. > **Facing a problem? Check the [Wiki FAQ](https://github.com/baomidou/dynamic-datasource/wiki) first.**
  297. > The most frequently reported issues — `@DS` not switching, startup errors, switching inside transactions,
  298. > threads/async, pool parameters not taking effect — are distilled into troubleshooting checklists; most
  299. > questions are answered there. File an issue only when it is a genuine bug or not covered by the FAQ.
  300. - **Documentation** — <https://doc.xiuceyun.cn>: the complete guide — tutorials, configuration keys,
  301. integrations and advanced usage, with a Chinese/English switcher and versioned docs (the former
  302. paid content is now free for everyone).
  303. - **Wiki (English)** — <https://github.com/baomidou/dynamic-datasource/wiki/Home-English>
  304. - **Wiki (简体中文)** — <https://github.com/baomidou/dynamic-datasource/wiki>
  305. The Wiki focuses on FAQ & troubleshooting checklists distilled from hundreds of historical issues;
  306. treat the documentation site as the complete reference.
  307. - **FAQ picks** — [@DS not working checklist](https://github.com/baomidou/dynamic-datasource/wiki/DS-Not-Working-Checklist) ·
  308. [switching inside transactions](https://github.com/baomidou/dynamic-datasource/wiki/DS-Switching-Inside-Transactions) ·
  309. [startup errors](https://github.com/baomidou/dynamic-datasource/wiki/Startup-Errors) ·
  310. [threads & async](https://github.com/baomidou/dynamic-datasource/wiki/DS-And-Threads) ·
  311. [all FAQs](https://github.com/baomidou/dynamic-datasource/wiki)
  312. - **Samples** — <https://github.com/dynamic-datasource/dynamic-datasource-samples>
  313. - **QQ group** (Chinese-speaking community) — [join](https://shang.qq.com/wpa/qunwpa?idkey=ded31006508b57d2d732c81266dd2c26e33283f84464e2c294309d90b9674992)
  314. - **Legacy docs (Kancloud, historical reference only)** — <https://www.kancloud.cn/tracy5546/dynamic-datasource>
  315. ## AI assistant support (Skill)
  316. This repository ships an Agent Skill in the open `SKILL.md` format ([`skills/dynamic-datasource`](./skills/dynamic-datasource/SKILL.md)). Once installed into your project, AI coding assistants (Qoder / Claude Code / Cursor, …) can answer, in your project's context: **basic installation & minimal configuration**, and **troubleshooting for the most common problems** — "why is datasource switching failing / `@DS` not working", startup errors, switching inside transactions, threads/async, pool parameters, password encryption.
  317. Install (any one):
  318. - skills CLI: `npx skills add baomidou/dynamic-datasource`
  319. - Manual: copy the `skills/dynamic-datasource/` directory into your project's `.qoder/skills/` (Qoder) or `.claude/skills/` (Claude Code) directory
  320. - Or simply paste the [`SKILL.md`](./skills/dynamic-datasource/SKILL.md) link to your AI assistant and let it answer from this context
  321. ## Contributing, Security and License
  322. - Contributions are welcome — read [CONTRIBUTING.md](./CONTRIBUTING.md) for the Gradle/toolchain
  323. setup, the `nativeTest` gate and the release procedure.
  324. - Please do **not** open a public issue for a vulnerability; follow [SECURITY.md](./SECURITY.md).
  325. - Released under the [Apache License 2.0](./LICENSE). Maintained since 2018 by the
  326. [baomidou organisation](https://github.com/baomidou); the canonical repository is
  327. [baomidou/dynamic-datasource](https://github.com/baomidou/dynamic-datasource).
  328. <p align="center">
  329. <a href="https://github.com/baomidou/dynamic-datasource/stargazers">
  330. <img src="https://img.shields.io/github/stars/baomidou/dynamic-datasource?style=social" alt="Stars" />
  331. </a>
  332. </p>

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.