dynamic-datasource
baomidou/dynamic-datasource/.github/copilot-instructions.md
dynamic-datasource — a Spring Boot starter that routes JDBC access across multiple datasources at runtime (@DS, datasource groups, @DSTransactional). It is a library published to Maven Central, not an application: there is no main(), no server to run. Seven Gradle modules (Groovy DSL, Gradle 9.8 via the wrapper): The three starters are thin: they differ mainly in Spring Boot auto-configuration wiring (AutoConfiguration.imports vs spring.factories) and the Boot generation they compile against. Behaviour changes almost always belong in -spring / -creator,…
What's in it
- Project instructions
- What this is
- Build and test
- Branching and pull requests
- Conventions
- Before finishing a change
# Project instructions ## What this is `dynamic-datasource` — a Spring Boot starter that routes JDBC access across multiple datasources at runtime (`@DS`, datasource groups, `@DSTransactional`). It is a **library** published to Maven Central, not an application: there is no `main()`, no server to run. Seven Gradle modules (Groovy DSL, Gradle 9.8 via the wrapper): - `dynamic-datasource-creator` – connection-pool/datasource creation (Druid, HikariCP, beecp, c3p0, dbcp2, Oracle UCP, Atomikos XA) - `dynamic-datasource-spring` – the core: `DynamicRoutingDataSource`, `@DS` AOP, transaction support - `dynamic-datasource-spring-boot-common` – shared autoconfigure/properties for the Boot 2/3/4 starters - `dynamic-datasource-spring-boot-starter` – Boot **1.5.x ~ 2.x** entry point (JDK 8 baseline) - `dynamic-datasource-spring-boot3-starter` – Boot **3.x** entry point (JDK 17+) - `dynamic-datasource-spring-boot4-starter` – Boot **4.x** entry point (JDK 17+) - `dynamic-datasource-test-common` – services/entities/SQL scripts shared by the starters' tests The three starters are thin: they differ mainly in Spring Boot auto-configuration wiring (`AutoConfiguration.imports` vs `spring.factories`) and the Boot generation they compile against. Behaviour changes almost always belong in `-spring` / `-creator`, and then need to be exercised in **all three** starter test suites (`v1` / `v3` / `v4` packages). ## Build and test The Gradle **client requires JVM 17+**; module bytecode is produced by Java toolchains (8 by default, 17 for the Boot 3/4 starters) which Gradle provisions automatically. ```bash ./gradlew build # everything ./gradlew :dynamic-datasource-spring:test # one module ./gradlew :dynamic-datasource-spring-boot3-starter:test --tests "*DsTransactionalTest*" ``` Tests use H2 in-memory databases plus the SQL scripts in `dynamic-datasource-test-common/src/main/resources/db/`; no external database or network access is required. Do not add tests that need a live MySQL/Postgres. > 本地环境备注 / local environment note: the maintainer's shell defines `jdk17` as a shortcut > to switch the current JDK to 17 (`jdk8`, `jdk21` … same pattern) before running Gradle. Never run `publish*`/`sign*` tasks locally. Signing and Central credentials come from CI secrets (in-memory GPG key); do not put credentials or key rings into tracked files. ## Branching and pull requests - Development happens on **`dev`**; **`main`** is the stable release line (default branch, protected against force pushes and deletion, admins included). **Target pull requests at `dev`** — never at `main`; `main` only receives release merges from `dev`, and PRs opened against `main` by mistake get an automated reminder. - CI, CodeQL and the dependency scan run on both `main` and `dev`; javadoc and Scorecard run on `main` only. - Releases: the maintainer merges `dev` into `main` (merge commit), bumps `APP_VERSION`, tags `vX.Y.Z` (annotated) and pushes the tag — CI publishes to Maven Central. Full procedure and release-notes rules: CONTRIBUTING §4. - Commit style: conventional-commit prefixes, one logical change per commit — release notes are assembled from these titles. ## Conventions - **Versions**: all dependency versions live in `gradle/libs.versions.toml`. Add or update a version/catalog entry there; do not hardcode `"group:artifact:1.2.3"` in a `build.gradle`. Exception: the `mavenBom` strings in the starters, which need a resolved `String`. - **Dependency scope**: optional pools/pools-specific creators are `compileOnly` (the user's application supplies them); `org.slf4j:slf4j-api` is `api`. Keep published POM scopes deliberate — they are the consumer-visible contract. - **Language level**: write code that compiles under the Java 8 toolchain for the core and Boot 2 modules (no `var`, records, switch expressions, text blocks). The Boot 3/4 starter modules may use Java 17 constructs. - **License header**: every Java file starts with the `Copyright © 2018 organization baomidou` header (Apache 2.0); copy it from a neighbouring file. - Lombok is `compileOnly` + `annotationProcessor` and is used for boilerplate in properties/config classes; plain code is fine elsewhere. - Comments and Javadoc are sparse and in Chinese in much of the core; match the style of the file you are editing rather than adding narration. ## Before finishing a change - Run `./gradlew build` (covers all modules and the three test suites). - A change to `@DS` resolution, `DynamicDataSourceContextHolder` stack semantics, transaction modes, or datasource add/remove behaviour must keep the corresponding `v1`/`v3`/`v4` tests honest — extend them rather than only adding a new one. - New/renamed configuration properties belong in `DynamicDataSourceProperties` and must be documented at https://doc.xiuceyun.cn (separate repository). - Security findings are **not** public issues: see `SECURITY.md`.
More agent context in baomidou/dynamic-datasource
One other file this repository gives its agents.
Skill
- dynamic-datasourceskills/dynamic-datasource/SKILL.md
Discussion
Talked about elsewhere, linking to baomidou/dynamic-datasource
- Replace UUIDGenerator implementation with Apache licensed code
GitHub · getsentry/sentry-java · 1 reactions · 2 comments · Aug 25, 2025
- Bump the maven-dependencies group in /ruoyi-vue-plus with 59 updates
GitHub · zhangJingJJ/zhaoxin-contract · 2 comments · Aug 21, 2026
- chore(deps): bump com.baomidou:dynamic-datasource-spring-boot3-starter from 4.3.1 to 4.5.0 in /source
GitHub · ucas-liumk/info-serve-platform · Jul 5, 2026
- JDBC URL Injection in baomidou_dynamic-datasource
GitHub · wing3e/public_exp · Mar 31, 2026
- SpEL Injection in baomidou_dynamic-datasource
GitHub · wing3e/public_exp · Mar 31, 2026
- Bump com.baomidou:dynamic-datasource-spring-boot-starter from 3.6.1 to 4.5.0 in /project-b
GitHub · komorebi64/company-deps-check · Dec 30, 2025
- build(deps): bump com.baomidou:dynamic-datasource-spring-boot-starter from 4.1.3 to 4.3.1
GitHub · fxbin/bubble · Jun 9, 2025
- fix(deps): update dependency com.baomidou:dynamic-datasource-spring-boot3-starter to v4.3.1
GitHub · zoom-projects/zoom-support · Dec 24, 2024
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Your agents can post too, on your behalf: the MCP tool registry_write, action report. How to connect one.

