Repository navigation
fix: let pool creators built with the no-arg constructor create data sources - #825
Merged
huayanYu merged 2 commits intoOct 20, 2026
Merged
Conversation
dynamic-datasource-creator and dynamic-datasource-spring-boot-common both hardcoded com.oracle.database.jdbc:ucp:23.4.0.24.05. The version now lives in gradle/libs.versions.toml with the other dependency versions, so that the creator tests can use the same entry. The compileClasspath dependency trees of both modules are unchanged.
…sources HikariDataSourceCreator, BeeCpDataSourceCreator, Dbcp2DataSourceCreator, C3p0DataSourceCreator and OracleUcpDataSourceCreator leave their global pool config null when they are built with the no-arg constructor, and createDataSource passes it to ConfigMergeCreator#create as is. For these five creators the config class and the target class differ, so the merge went on and invoked the getters on the null config. Every createDataSource call threw a NullPointerException, whatever the DataSourceProperty contained. The starters always pass the global config from DynamicDataSourceProperties, so only code that wires dynamic-datasource by hand ran into it. ConfigMergeCreator now treats a null global config as "no global defaults", as DruidConfigUtil#merge already does, and applies only the per-datasource settings. None of the five config classes has defaults of its own, so this is the same result as passing an empty global config. A non-null global config is merged as before. ConfigMergeCreatorTest covers both merge paths with a null global config, compares the result with an empty global config and keeps the merge order for a non-null one. NoArgsDataSourceCreatorTest runs the reproducer from baomidou#821 for all five creators, and each case checks that one per-datasource option reaches the data source. The pools are compileOnly, so the creator module declares them again for its tests. Two more test runtime dependencies are needed: spring-jcl, because the Boot 2 BOM excludes commons-logging from commons-dbcp2, and ojdbc8, because the method signatures of PoolDataSourceImpl reference ojdbc types and the ojdbc11 that oracle-spring-boot-starter-ucp brings cannot load on JDK 8.
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更类型 / What kind of change does this PR introduce?
描述 / The description of the PR
说明为什么需要这个改动,而不只是改了什么;关联对应的 issue(
Fixes #123)。Fixes #821
HikariDataSourceCreator,BeeCpDataSourceCreator,Dbcp2DataSourceCreator,C3p0DataSourceCreatorandOracleUcpDataSourceCreatorleave their global pool confignullwhen they are built with the no-arg constructor.ConfigMergeCreator#createthen invoked the getters on thatnullconfig, so everycreateDataSourcecall threw aNullPointerException. The starters always pass the global config fromDynamicDataSourceProperties, so only code that wires dynamic-datasource by hand ran into it, such as dynamic-datasource/dynamic-datasource-samples#61.This PR has two commits:
build: declare the Oracle ucp version in the version catalog:dynamic-datasource-creatoranddynamic-datasource-spring-boot-commonboth hardcodedcom.oracle.database.jdbc:ucp:23.4.0.24.05. The version now lives ingradle/libs.versions.toml, so that the tests in the next commit can use the same entry. ThecompileClasspathdependency trees of both modules are identical before and after.fix: let pool creators built with the no-arg constructor create data sourcesConfigMergeCreatortreats anullglobal config as "no global defaults", asDruidConfigUtil#mergealready does:mergeBasicandmergePropertiesskip the global config when it isnull, so only the per-datasource settings are applied. None of the five config classes has defaults of its own, sonew HikariDataSourceCreator()now gives the same result asnew HikariDataSourceCreator(new HikariCpConfig()), which is the expected behaviour described in the issue. A non-null global config is merged as before.ConfigMergeCreatorTestcovers both merge paths with anullglobal config, compares the result with an empty global config, and keeps the merge order for a non-null one.NoArgsDataSourceCreatorTestis the reproducer from the issue for all five creators. Each case sets one per-datasource option that differs from the pool's default and checks that it reaches the data source.compileOnly, so the creator module declares them again for its tests. Two more test runtime dependencies are needed.spring-jcl: the Boot 2 BOM excludescommons-loggingfromcommons-dbcp2, and a Boot application getsLogFactoryfromspring-jclin the same way.ojdbc8: the method signatures ofPoolDataSourceImplreference ojdbc types, so without ojdbc the introspection inConfigMergeCreatorfails withNoClassDefFoundError: oracle/jdbc/OracleShardingKeyBuilder, and theojdbc11thatoracle-spring-boot-starter-ucpbrings cannot load on the JDK 8 toolchain. Both are test scope only, so the published POMs do not change. The alternative was to leave UCP out ofNoArgsDataSourceCreatorTestand rely onConfigMergeCreatorTestalone, but then one of the five creators from the issue would have no test of its own.The tests are in
dynamic-datasource-creatorrather than in the shared Boot 2/3/4 scenarios. The starters always pass a non-null global config, so their auto-configuration never reaches this path. Of these five pools, the starters' test classpaths only carry HikariCP, and adding the others there would change which creators the auto-configuration registers.影响面 / Impact on the core contracts
本框架的核心契约很窄,改动通常会波及其中之一,请勾选并说明:
@DS解析 /DynamicDataSourceContextHolder的切换与栈语义(含多层嵌套、同类内部调用)@DSTransactional、savepoint、XA/Atomikos、Seata)GroupDataSource、strategy)ENC(...)加解密 / 配置属性(新增或改名配置项)新增/改名配置项时,请同步文档 https://doc.xiuceyun.cn 与
DynamicDataSourceProperties的 Javadoc。自检清单 / Checklist
./gradlew clean test通过(Gradle 客户端要求 17+;Boot 2 线模块由 JDK 8 toolchain 编译测试)./gradlew buildCopyright © 2018 organization baomidou)fix:/feat:/build:/docs:…),一个 commit 做一件事其他信息 / Other information
Verified locally with GraalVM CE 25.4.4.1 (JDK 25.0.4.1) running Gradle, on
dev@ 7c321c1 plus this change:NoArgsDataSourceCreatorTestcases fail with theNullPointerExceptionfrom the issue (ConfigMergeCreator.mergeBasic). So do the twoConfigMergeCreatorTestcases with anullglobal config, one inmergeBasicand one inmergeProperties. The case with a non-null global config passes.Repro.javaon JDK 17.0.20.1 with the pool versions listed in the issue: with the releaseddynamic-datasource-creator4.6.0 it prints the output shown in the issue. With the creator jar built from this branch, all ten lines print a data source class and the final call no longer throws../gradlew clean build --no-build-cache: all modules pass.nativeTestfordynamic-datasource-spring-boot3-starter(52 found, 46 passed, 6 skipped by@DisabledInNativeImage) anddynamic-datasource-spring-boot4-starter(48 found, 46 passed, 2 skipped): pass. No reachability metadata is needed: the fix only skips the reflective reads on anullglobal config, and a non-null one goes through the same reflection as before.javadoc -Xdoclint:all,-missingwith JDK 8 (-packagefor the tests).