Repository navigation
Description
想解决的问题 / The problem to solve
dynamic-datasource-spring declares mybatis-spring as api (build.gradle#L42, 2.1.2), and dynamic-datasource-spring-boot4-starter overrides it with api("org.mybatis:mybatis-spring:4.0.0") (build.gradle#L49). The only class that uses it is AtomikosTransactionFactory, and that bean is only created under @ConditionalOnClass({AtomikosDataSourceBean.class, TransactionFactory.class}) (DynamicDataSourceCreatorAutoConfiguration.java#L154). Still, every app gets mybatis-spring on its classpath, MyBatis or not.
On Boot 4 it also overrides the version the MyBatis starter needs. mybatis-spring-boot-starter 4.1.0 brings mybatis-spring 4.1.0 at the same depth as the 4.0.0 from our starter, so Maven keeps whichever is declared first. In dynamic-datasource-samples, 12 of the 13 Boot 4 modules I checked resolved 4.0.0. That includes modules that don't use MyBatis at all (beetlsql, consul, nacos, jdbc-template), and the five modules on mybatis-spring-boot-starter 4.1.0 that declare our starter first. Those end up running mybatis-spring-boot-starter 4.1.0 on mybatis-spring 4.0.0, without the AOT fixes from mybatis/spring#1238 and #1239. Only the module that declares mybatis-spring-boot-starter first got 4.1.0. On Boot 3 there is no override, so apps without their own MyBatis starter get 2.1.2, which is built against Spring 5.3.
期望的行为 / Proposed behaviour
Declare mybatis-spring as compileOnly in dynamic-datasource-spring, the same way mybatis-plus, p6spy and seata already are (MyBatis core itself already comes in through the compileOnly mybatis-plus), and drop the api line from the Boot 4 starter. Apps that use MyBatis get mybatis-spring from mybatis-spring-boot-starter or the MyBatis-Plus starters anyway.
I'd also add SpringManagedTransactionFactory to that @ConditionalOnClass. AtomikosTransactionFactory extends it, so an app with Atomikos and MyBatis core but without mybatis-spring would otherwise fail when the bean is created. @DS, @DSTransactional and Seata don't touch mybatis-spring, and the Atomikos XA path keeps working whenever mybatis-spring is on the classpath.
现在的替代方案 / Current workaround
The samples pin org.mybatis:mybatis-spring to 4.1.0 in the parent POM's dependencyManagement (dynamic-datasource/dynamic-datasource-samples#56). Excluding it from the starter works too, but every module would have to repeat the exclusion.
影响范围 / Which part is affected
构建与发布 (Gradle / CI)
提交前确认 / Preflight
- 我已搜索过 open/closed issues 与 Discussions,没有重复建议
- 我愿意提交 PR 实现它(可选,但会大大提高被接纳的概率)
Activity
linghengqian commentedon Oct 16, 2026
I am working on the current issue.
linghengqian commentedon Oct 17, 2026
linghengqian commentedon Oct 17, 2026
Fixesstatement serves no purpose.