Skip to content

Commit 8b4e0bd

Browse files
committed
Migrate samples to Spring Boot 4 with per-version layout (spring-boot-2/3/4) and Testcontainers coverage
1 parent fe95525 commit 8b4e0bd

248 files changed

Lines changed: 1700 additions & 622 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ jobs:
1010
test-hotspot-jdk-ci:
1111
name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }}
1212
runs-on: ${{ matrix.os }}
13-
timeout-minutes: 60
13+
# 集成测试要拉取较大的镜像(nacos/seata/mysql/postgres/consul),冷缓存时多留一些时间。
14+
timeout-minutes: 120
1415
strategy:
1516
matrix:
1617
os: [ 'ubuntu-latest' ]
@@ -42,14 +43,9 @@ jobs:
4243
distribution: 'temurin'
4344
java-version: ${{ matrix.java-version }}
4445
cache: 'maven'
45-
- name: Build datasource test with Maven
46-
run: |
47-
./mvnw -am -pl datasource-samples/druid-sample -T1C -B -e clean test
48-
- name: Build orm test with Maven
49-
run: |
50-
./mvnw -am -pl orm-samples/mybatis-sample -T1C -B -e clean test
51-
- name: Build third-part test with Maven
46+
- name: Build spring-boot-2 samples with Maven
47+
# 主代码保持 Java 8 兼容;测试需要 testcontainers 2.x(加载要求 Java 17+),
48+
# 因此 JDK 8 任务只做编译验证,测试在上面的 JDK 17/21 任务中执行。
5249
run: |
53-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-4.x-spring-sample -T1C -e clean test
54-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-core-sample -T1C -e clean test
55-
./mvnw -am -pl third-part-samples/shardingsphere-sample/shardingsphere-jdbc-5.x-spring-sample -T1C -e clean test
50+
./mvnw -am -pl spring-boot-2/config-nacos-sample -T1C -B -e clean compile
51+
./mvnw -am -pl spring-boot-2/shardingsphere-jdbc-4.x-spring-sample -T1C -B -e clean compile

‎README.md‎

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
11
# 演示例子
22

3-
大部分数据库连接为 `h2database` 或通过 `testcontainers-java` 启动的 `mysql-server`,仅供测试。讨论不同情况,
3+
大部分数据库连接为 `h2database` 或通过 `testcontainers-java` 启动的 `mysql-server`,仅供测试。
44

5-
1. `com.baomidou:springboot3-sample` 可在 [OpenJDK 17, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试
6-
2. 除开 `com.baomidou:springboot3-sample`, 其他子模块均可在 [OpenJDK 8, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试
5+
示例按 Spring Boot 版本分别存放在 `spring-boot-2`、`spring-boot-3`、`spring-boot-4` 文件夹下,
6+
每个文件夹都是独立的 Maven 聚合模块(版本对应的 `dynamic-datasource-spring-boot-starter` /
7+
`dynamic-datasource-spring-boot3-starter` / `dynamic-datasource-spring-boot4-starter` 见其下的 `pom.xml`):
8+
9+
- `spring-boot-2` 下的子模块运行在 Spring Boot 2.7.x,可在 [OpenJDK 8, OpenJDK 21] 的 JDK 范围及其下游发行版下执行单元测试
10+
- `spring-boot-3`(`springboot3-sample`)与 `spring-boot-4` 下的子模块分别运行在 Spring Boot 3.5.x / 4.0.x,
11+
需要在 [OpenJDK 17, ...] 的 JDK 范围及其下游发行版下执行单元测试
712

813
所有单元测试在 Github Actions 完成验证。你可能希望参考 [位于 Github Actions 的 CI 文件](./.github/workflows/ci.yml)。
914

10-
- add-remove-datasource 动态添加删除数据源的使用示例
11-
- all-datasource-sample 所有不同连接池使用示例(大乱炖,实际不建议)
15+
## Spring Boot 4(`spring-boot-4/`)
16+
17+
- add-remove-datasource-sample 动态添加删除数据源的使用示例
18+
- beetlsql-sample 集成 BeetlSQL 的使用示例
19+
- config-consul-sample 集成 Consul 配置中心的使用示例
1220
- druid-sample 集成mybatis和druid的使用示例
1321
- jdbc-template-sample 集成原生jdbcTemplate的使用示例
14-
- load-datasource-from-jdbc 通过数据库配置来启动数据源示例
22+
- load-datasource-from-jdbc-sample 通过数据库配置来启动数据源示例
1523
- mybatis-sample 集成原生mybatis的使用示例
16-
- mybatisplus2-sample 集成mybatisPlus2的使用示例
1724
- mybatisplus3-sample 集成mybatisPlus3的使用示例
1825
- name-pattern-sample 自定义切面的使用示例
19-
- nest-sample 嵌套切换数据源使用示例
2026
- quartz-sample 多数据源集成quartz示例
21-
- shardingsphere-jdbc-4.x-spring-sample 集成 ShardingSphere JDBC Spring Boot Starter 4.1.1 使用示例, 不再维护,
22-
参考 https://github.com/apache/shardingsphere/releases/tag/5.0.0-alpha
2327
- shardingsphere-jdbc-5.x-core-sample 集成 ShardingSphere JDBC Driver 5.5.2 使用示例
24-
- shardingsphere-jdbc-5.x-spring-sample 集成 ShardingSphere JDBC Spring Boot Starter 5.2.1 使用示例, 不再维护,
28+
- shardingsphere-jdbc-5.x-spring-sample 集成 ShardingSphere JDBC Driver 5.5.2 使用示例,
2529
参考 https://github.com/apache/shardingsphere/issues/22469
2630
- spel-sample 动态从外部参数spel来切换数据源的使用示例
2731
- tx-local-sample 本地事务示例项目★★★★★★必看★★★★★★
2832
- tx-seata-sample 基于seata的分布式事务集成使用示例
2933

34+
## Spring Boot 3(`spring-boot-3/`)
35+
36+
- springboot3-sample Spring Boot 3 使用示例
37+
38+
## Spring Boot 2(`spring-boot-2/`)
39+
40+
以下示例暂时无法迁移到高版本,予以保留:
41+
42+
- config-nacos-sample 集成 Nacos 配置中心的使用示例(`com.alibaba.boot` 坐标未变,
43+
nacos 上游最新只有 0.3.0-RC 且仍基于 Spring Boot 2.x,没有 Boot 3/4 版本,暂无法迁移)
44+
- shardingsphere-jdbc-4.x-spring-sample 集成 ShardingSphere JDBC Spring Boot Starter 4.1.1 使用示例, 不再维护,
45+
参考 https://github.com/apache/shardingsphere/releases/tag/5.0.0-alpha
46+
47+
## 单元测试说明
48+
49+
- 纯 H2 的模块(`mybatisplus3-sample`、`beetlsql-sample`、`jdbc-template-sample`、`name-pattern-sample`、
50+
`add-remove-datasource-sample`、`load-datasource-from-jdbc-sample`、`druid-sample`、`spel-sample`、
51+
`shardingsphere-jdbc-5.x-spring-sample`)可直接 `mvn test`,无需外部服务。
52+
- 涉及外部中间件的模块使用 [Testcontainers](https://java.testcontainers.org/) 在测试中启动容器,
53+
本地与 CI 运行测试都需要可用的 Docker 环境:
54+
- `quartz-sample`:`mysql:8.4.7-oraclelinux9`
55+
- `tx-local-sample`:`postgres:16-alpine`(测试资源里用 `init-schemas.sql` 预建 schema)
56+
- `tx-seata-sample`:`postgres:16-alpine` + `apache/seata-server:2.6.0`(与客户端版本对齐)
57+
- `config-consul-sample`:`hashicorp/consul:1.15`(向 KV 写入 `dynamic-datasource/application/data`)
58+
- `config-nacos-sample`:`nacos/nacos-server:v2.3.2`(0.2.x starter 内含 2.x 客户端,走 gRPC,
59+
测试按实际映射端口动态计算 `nacos.server.grpc.port.offset`)
60+
- `shardingsphere-jdbc-5.x-core-sample`:`mysql:8.4.7-oraclelinux9`
61+
- `spring-boot-2` 下模块的主代码保持 Java 8 兼容;其测试依赖 testcontainers 2.x(加载需要 Java 17+),
62+
因此 JDK 8 的 CI 任务仅做 `clean compile`,完整测试在 JDK 17/21 任务中执行。
63+
3064
## Contributing
3165

3266
我们欢迎社区的贡献。围绕此 git 的讨论与协作应通过 https://github.com/baomidou/dynamic-datasource/issues 进行。
3367
在提交 Pull Request 之前, 请在本地通过 [OpenJDK 17, OpenJDK 21] 的 JDK 范围下完成此命令的验证。
3468
我们鼓励通过 `SDKMAN!` 或 `version-fox/vfox` 切换到 `21.0.2-graalce` 来验证。
3569

36-
针对 IntelliJ IDEA 等 IDE,项目的语言级别应设置为 JDK 8,对于单独的 `com.baomidou:springboot3-sample` 子模块,语言级别应设置为 JDK 17。
70+
针对 IntelliJ IDEA 等 IDE,`spring-boot-2` 下模块的语言级别应设置为 JDK 8,`spring-boot-3` 与 `spring-boot-4` 下模块的语言级别应设置为 JDK 17。
3771
下文讨论不同情况下可能的测试流程,
3872

39-
### Ubuntu 24.04
73+
### Ubuntu 26.04.1
4074

4175
假设 `SDKMAN!` 和 `Docker Engine` 已安装,在 Bash 执行如下命令,
4276

‎config-samples/config-consul-sample/pom.xml‎

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎config-samples/pom.xml‎

Lines changed: 0 additions & 20 deletions
This file was deleted.

‎datasource-samples/pom.xml‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎features-samples/pom.xml‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎no-ds-samples/pom.xml‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎orm-samples/mybatisplus3-sample/src/main/java/com/baomidou/samples/mybatisplus3/service/impl/UserServiceImpl.java‎

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎orm-samples/pom.xml‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)