From 620444cdbed6e3769165611dcb476f00eb816166 Mon Sep 17 00:00:00 2001 From: Ling Hengqian Date: Wed, 3 Jan 2024 08:34:06 +0800 Subject: [PATCH] Fixes CI errors caused by Druid and Spring Framework changes (#613) --- .github/workflows/ci.yml | 10 +++---- CONTRIBUTING.md | 11 ++++--- README.md | 4 +++ dynamic-datasource-spring-boot-common/pom.xml | 5 ---- .../pom.xml | 5 ++++ .../DruidDynamicDataSourceConfiguration.java | 0 .../pom.xml | 5 ++++ .../DruidDynamicDataSourceConfiguration.java | 30 +++++++++++++++++++ native-image/extra-filter.json | 27 +++++++++-------- pom.xml | 6 ++-- 10 files changed, 73 insertions(+), 30 deletions(-) rename {dynamic-datasource-spring-boot-common => dynamic-datasource-spring-boot-starter}/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java (100%) create mode 100644 dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 918d58c7..d63ef921 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,12 +28,12 @@ jobs: test-graalvm-ce-ci: name: NativeTest CI - GraalVM CE ${{ matrix.java-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} - timeout-minutes: 90 + timeout-minutes: 30 continue-on-error: true strategy: matrix: os: [ ubuntu-latest ] - java-version: [ '21' ] + java-version: [ '21.0.1' ] steps: - uses: actions/checkout@v3 - uses: graalvm/setup-graalvm@v1 @@ -48,11 +48,11 @@ jobs: test-hotspot-jdk-ci: name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} - timeout-minutes: 60 + timeout-minutes: 30 strategy: matrix: os: [ ubuntu-latest ] - java-version: [ '17', '21-ea' ] + java-version: [ '17', '21' ] steps: - uses: actions/checkout@v3 - name: Setup java @@ -67,7 +67,7 @@ jobs: test-minimum-jdk-ci: name: Test CI - JDK ${{ matrix.java-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} - timeout-minutes: 60 + timeout-minutes: 30 strategy: matrix: os: [ ubuntu-latest ] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11f5b272..c35bfac7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ Git Mirror 位于 https://github.com/baomidou/dynamic-datasource 。 当项目导入 IntelliJ IDEA 或 VSCode 时,IDE 对项目的语言级别应当设置为 8。 对于单独的 `com.baomidou:dynamic-datasource-spring-boot3-starter` 子模块,IDE 的语言级别应当设置为 17。 -提交 PR 前,应在 OpenJDK 17 下执行 `./mvnw -T1C -B clean test` 以验证更改是否未破坏单元测试。若有需要请补充或更改单元测试。 +提交 PR 前,应在 OpenJDK 17 下执行 `./mvnw -T1C clean test` 以验证更改是否未破坏单元测试。若有需要请补充或更改单元测试。 假设贡献者处于新的 Ubuntu 22.04.3 LTS 实例下,其可通过如下 bash 命令来通过 SDKMAN! 管理 JDK 和工具链,并执行单元测试。 @@ -22,7 +22,7 @@ sdk use java 17.0.8-ms git clone git@github.com:baomidou/dynamic-datasource.git cd ./dynamic-datasource/ -./mvnw -T1C -B clean test +./mvnw -T1C clean test ``` ## 2.1. Execute NativeTest under GraalVM Native Image @@ -41,8 +41,8 @@ failed to discover tests 的测试库。 sudo apt install unzip zip curl sed -y curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" -sdk install java 21-graalce -sdk use java 21-graalce +sdk install java 21.0.1-graalce +sdk use java 21.0.1-graalce sudo apt-get install build-essential libz-dev zlib1g-dev -y git clone git@github.com:baomidou/dynamic-datasource.git @@ -68,7 +68,7 @@ System Property 屏蔽部分单元测试在 GraalVM Native Image 下运行。 已有的 GraalVM Reachability Metadata 文件。可通过如下 bash 命令简单处理此流程。贡献者仍可能需要手动调整具体的 JSON 条目,并在适当的时候 调整 Maven Profile 和 GraalVM Tracing Agent 的 Filter 链。 -以下命令仅为 `dynamic-datasource-spring-boot3-starter` 生成 Conditioanl 形态的 GraalVM Reachability Metadata 的一个举例。 +以下命令仅为 `dynamic-datasource-spring-boot3-starter` 生成 Conditional 形态的 GraalVM Reachability Metadata 的一个举例。 对于测试类和测试文件独立使用的 GraalVM Reachability Metadata,贡献者应该放置到相关子模块对应的 `${project.basedir}/src/test/resources/META-INF/native-image/${project.artifactId}-test-metadata/` 文件夹下。`${}` 内为 @@ -78,7 +78,6 @@ POM 4.0 的常规系统变量,自行替换。 git clone git@github.com:baomidou/dynamic-datasource.git cd ./dynamic-datasource/ ./mvnw -PgenerateMetadata -DskipNativeTests -e -T1C clean test native:metadata-copy -./mvnw -PnativeTestInSpringBoot -T1C -e clean test ``` 请手动删除无任何具体条目的 JSON 文件。 diff --git a/README.md b/README.md index e0391e05..a487577c 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ dynamic-datasource-spring-boot-starter 是一个基于springboot的快速集成 详细文档 https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611 +## 贡献 | Contributing + +我们欢迎社区的贡献,请查看 [CONTRIBUTING.md](./CONTRIBUTING.md) 。 + # 特性 - 支持 **数据源分组** ,适用于多种场景 纯粹多库 读写分离 一主多从 混合模式。 diff --git a/dynamic-datasource-spring-boot-common/pom.xml b/dynamic-datasource-spring-boot-common/pom.xml index 97330ae2..d3a5e878 100644 --- a/dynamic-datasource-spring-boot-common/pom.xml +++ b/dynamic-datasource-spring-boot-common/pom.xml @@ -56,11 +56,6 @@ org.springframework.boot spring-boot-starter-aop - - com.alibaba - druid-spring-boot-starter - true - org.springframework.boot spring-boot-configuration-processor diff --git a/dynamic-datasource-spring-boot-starter/pom.xml b/dynamic-datasource-spring-boot-starter/pom.xml index cbbb5fbd..628d8f4d 100644 --- a/dynamic-datasource-spring-boot-starter/pom.xml +++ b/dynamic-datasource-spring-boot-starter/pom.xml @@ -24,6 +24,11 @@ spring-boot-starter-web true + + com.alibaba + druid-spring-boot-starter + true + org.springframework.boot spring-boot-configuration-processor diff --git a/dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java b/dynamic-datasource-spring-boot-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java similarity index 100% rename from dynamic-datasource-spring-boot-common/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java rename to dynamic-datasource-spring-boot-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java diff --git a/dynamic-datasource-spring-boot3-starter/pom.xml b/dynamic-datasource-spring-boot3-starter/pom.xml index d00f7947..0dc13f35 100644 --- a/dynamic-datasource-spring-boot3-starter/pom.xml +++ b/dynamic-datasource-spring-boot3-starter/pom.xml @@ -29,6 +29,11 @@ spring-boot-starter-web true + + com.alibaba + druid-spring-boot-3-starter + true + org.springframework.boot spring-boot-configuration-processor diff --git a/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java new file mode 100644 index 00000000..a5ff7ce7 --- /dev/null +++ b/dynamic-datasource-spring-boot3-starter/src/main/java/com/baomidou/dynamic/datasource/spring/boot/autoconfigure/DruidDynamicDataSourceConfiguration.java @@ -0,0 +1,30 @@ +package com.baomidou.dynamic.datasource.spring.boot.autoconfigure; + +import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure; +import com.alibaba.druid.spring.boot3.autoconfigure.properties.DruidStatProperties; +import com.alibaba.druid.spring.boot3.autoconfigure.stat.DruidFilterConfiguration; +import com.alibaba.druid.spring.boot3.autoconfigure.stat.DruidSpringAopConfiguration; +import com.alibaba.druid.spring.boot3.autoconfigure.stat.DruidStatViewServletConfiguration; +import com.alibaba.druid.spring.boot3.autoconfigure.stat.DruidWebStatFilterConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +/** + * 从原生DruidDataSourceAutoConfigure复制 + * + * @author TaoYu + * @since 1.1.0 + */ +@Configuration +@ConditionalOnClass(DruidDataSourceAutoConfigure.class) +@EnableConfigurationProperties({DruidStatProperties.class}) +@Import({ + DruidSpringAopConfiguration.class, + DruidStatViewServletConfiguration.class, + DruidWebStatFilterConfiguration.class, + DruidFilterConfiguration.class}) +public class DruidDynamicDataSourceConfiguration { + +} diff --git a/native-image/extra-filter.json b/native-image/extra-filter.json index d4ea3b70..d3e36acc 100644 --- a/native-image/extra-filter.json +++ b/native-image/extra-filter.json @@ -1,32 +1,35 @@ { "rules": [ {"includeClasses": "**"}, + {"excludeClasses": "java.lang.management.**"}, {"excludeClasses": "jdk.management.**"}, {"excludeClasses": "com.sun.management.**"}, {"excludeClasses": "sun.management.**"}, {"excludeClasses": "javax.management.**"}, + {"excludeClasses": "java.**"}, {"includeClasses": "java.util.Properties"}, {"includeClasses": "java.lang.Thread"}, + {"excludeClasses": "javax.naming.**"}, + {"excludeClasses": "javax.sql.**"}, {"excludeClasses": "sun.misc.**"}, {"excludeClasses": "sun.security.**"}, + + {"excludeClasses": "com.alibaba.druid.**"}, + {"excludeClasses": "com.baomidou.mybatisplus.**"}, + {"excludeClasses": "com.fasterxml.jackson.**"}, {"excludeClasses": "com.ibm.icu.text.**"}, - {"excludeClasses": "javax.naming.**"}, - {"excludeClasses": "javax.sql.**"}, - {"excludeClasses": "org.h2.**"}, - {"excludeClasses": "oracle.ucp.**"}, - {"excludeClasses": "org.apache.tomcat.jdbc.**"}, - {"excludeClasses": "org.apache.commons.**"}, {"excludeClasses": "com.mchange.v2.**"}, {"excludeClasses": "com.zaxxer.**"}, - {"excludeClasses": "com.alibaba.druid.**"}, - {"excludeClasses": "org.springframework.**"}, - {"excludeClasses": "org.apache.ibatis.binding.**"}, {"excludeClasses": "jakarta.servlet.**"}, - {"excludeClasses": "com.fasterxml.jackson.**"}, - {"excludeClasses": "com.baomidou.mybatisplus.**"} - + {"excludeClasses": "oracle.ucp.**"}, + {"excludeClasses": "org.apache.commons.**"}, + {"excludeClasses": "org.apache.ibatis.**"}, + {"excludeClasses": "org.apache.tomcat.jdbc.**"}, + {"excludeClasses": "org.h2.**"}, + {"excludeClasses": "org.mybatis.spring.**"}, + {"excludeClasses": "org.springframework.**"} ], "regexRules": [ {"excludeClasses": ".*fixture*.*"}, diff --git a/pom.xml b/pom.xml index a449a047..9a71e959 100644 --- a/pom.xml +++ b/pom.xml @@ -62,12 +62,12 @@ 1.18.30 2.2.224 4.0.6 - 5.10.0 + 5.10.1 3.3.1 3.1.1 3.3.1 - 3.1.2 + 3.2.3 3.11.0 3.6.0 3.3.0 @@ -222,6 +222,8 @@ ${java.version} ${java.version} + + true