Spring Boot 3.0.6 REST API构建Native Image启动失败原因排查
Spring Boot 3.0.6 Native Image启动报No available JtaPlatform candidates的原因
核心原因
Spring Boot 3.0.6升级了Hibernate依赖(从6.1.7.Final到6.1.8.Final),该Hibernate版本在Native Image静态编译场景下,对JtaPlatform候选类的检测逻辑发生了变化,导致Spring Boot自动配置默认提供的NoJtaPlatform实现未被正确纳入Native镜像中。
Native Image是静态提前编译(AOT)技术,会剔除所有未被直接引用或标记为需要保留的类。在3.0.5版本中,Spring Boot的自动配置逻辑会确保NoJtaPlatform这类默认JtaPlatform实现被强制包含在Native镜像里;但3.0.6版本搭配新的Hibernate版本后,这部分逻辑的兼容处理出现了遗漏,启动时Hibernate无法找到可用的JtaPlatform候选,从而抛出BeanCreationException。
临时解决方法
- 显式指定JtaPlatform:在配置文件(
application.properties或application.yml)中添加以下配置,强制使用无事务管理器的JtaPlatform实现:spring.jpa.properties.hibernate.transaction.jta.platform=org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform - 强制包含类到Native镜像:在项目的
native-image.properties文件中添加参数,确保该类在编译时被初始化并包含:--initialize-at-build-time=org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
内容的提问来源于stack exchange,提问作者BullyWiiPlaza
相关产品推荐
相关产品推荐

