Repository navigation
Conversation
dynamic-datasource supports Atomikos XA since long ago, but neither the documentation nor the samples ever covered it: the docs site only mentions Atomikos in a feature list, the wiki has no page, and the samples repo has tx-local / tx-seata but nothing for Atomikos. This adds the missing piece. - new spring-boot-4/tx-atomikos-sample: Boot 4.1.1 + Atomikos 6.0.1 (jakarta) + two H2 XA datasources, placeOrder spans order/account in one JTA transaction with 2PC commit and rollback, verified by 3 tests (no Docker). - pins ds.version 4.7.0 in the module only: 4.6.0 throws NoSuchMethodError: setReapTimeout(int) under Atomikos 6 (baomidou/dynamic-datasource#822); drop the override once 4.7.0 ships. - atomikos.version + jakarta-classifier dependencyManagement in spring-boot-4-samples. - documents the four non-obvious wiring points in the module README: Boot 4 no longer auto-configures the Atomikos transaction manager, jakarta.transaction-api is provided-scope, Spring @transactional breaks @ds routing with MyBatis (one SqlSession per transaction), and XA pools never commit init scripts. - native image opt-out with rationale in ci.yml, following tx-seata-sample.
Contributor
Author
|
更新:#823(Atomikos 6 setReapTimeout 修复)已合入主仓库 dev(commit 2ea99ea)。本示例在模块内覆盖 ds.version=4.7.0,等该版本发布后 CI 即转绿;已用 dev 最新代码本地发布 4.7.0 复跑,3/3 测试通过。4.7.0 发布后根 pom 的 ds.version 统一升级时,模块内的版本覆盖可删除。 |
Adds the XA datasource class table, the Atomikos pool parameter table and the programmatic JTA snippet, so the module no longer needs a separate wiki page to be complete.
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.
背景
dynamic-datasource 很早就支持 Atomikos XA,但文档与示例一直空缺:
has_wiki=false),内容不可见,仓库内也没有 Atomikos 说明;type: com.atomikos.jdbc.AtomikosDataSourceBean(缺省时 Hikari 创建器会接管并把 XA 数据源类当作java.sql.Driver加载,启动直接失败)。本 PR 补齐示例:新增
spring-boot-4/tx-atomikos-sample,并把实践中的四个坑写进模块 README(依赖版本窗口、Boot 4 的 JTA 手工装配、@Transactional与多数据源 MyBatis 的冲突、XA 建表注意点),模块 README 自成体系。示例内容
Boot 4.1.1 + Atomikos 6.0.1(jakarta)+ 两个 H2 XA 数据源(order / account),
OrderService#placeOrder在一个 JTA 事务里跨库写入,3 个测试覆盖:XA 数据源与 JTA 装配、两阶段提交成功、余额不足时两个库一起回滚。无需 Docker,本地
./mvnw -pl spring-boot-4/tx-atomikos-sample test即可跑。README 里记录了四个非显然的装配点:
UserTransactionManager+JtaTransactionManager;且
transactions-jta的jakarta.transaction-api是 provided 作用域,不显式引入会回退成JdbcTransactionManager;@Transactional:MyBatis-Spring 会把整个事务复用同一个 SqlSession/连接,事务内
@DS切换失效,故用编程式 JTA;AtomikosTransactionFactory;datasource.*.init.schema建表(Atomikos 非事务连接关闭时回滚未提交 DDL)。版本依赖说明(重要)
模块内覆盖
ds.version=4.7.0:dynamic-datasource 4.6.0 在 Atomikos 6 下启动即抛NoSuchMethodError: setReapTimeout(int)(baomidou/dynamic-datasource#822,修复 PR #823 已合入 dev),该修复预计随 4.7.0 发布。4.7.0 发布前本模块的 Test CI 会因依赖不存在而失败,发布后转绿;
届时根 pom 的
ds.version统一升级到 4.7.0 后,模块内的覆盖可删除。其余 15 个示例仍固定 4.6.0,不受影响。已本地验证:以 dev(含 #823)本地发布 4.7.0 后,模块 3/3 测试通过;spotless / license / checkstyle 均 0 违规。
其他变更
spring-boot-4/pom.xml:集中声明atomikos.version(6.0.1,jakarta classifier)并注册模块;.github/workflows/ci.yml:native 任务排除说明补充 tx-atomikos-sample(Atomikos JTA/XA 需要额外 reachability metadata);.gitignore:忽略 Atomikos 事务日志tmlog*.log/transaction-logs/;README.md:Spring Boot 4 模块清单补充条目。