You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.X迁3.2.0遇ClassNotFoundException: ConfigurableTransactionManager

Spring Boot 3.2.0迁移时出现ConfigurableTransactionManager类找不到的异常

问题详情

将Spring Boot项目从2.X版本迁移至3.2.0版本,完成语法与依赖调整后启动,抛出核心异常:

java.lang.ClassNotFoundException: org.springframework.transaction.ConfigurableTransactionManager

异常触发点为TransactionManagerCustomizationAutoConfiguration中的platformTransactionManagerCustomizers Bean实例化失败。

已知情况:

  • 项目未使用@Transactional注解
  • 已引入spring-boot-starter-web依赖(该依赖默认包含spring-tx模块,而ConfigurableTransactionManager属于此模块)
  • 查阅官方迁移指南未发现需手动定义该类实现的要求
  • 已将javax.inject.Inject替换为jakarta.inject.Inject,甚至改用@Autowired,问题仍存在

原因分析

  1. Camel版本不兼容:Spring Boot 3.x要求Camel 4.x及以上版本,若当前使用的Camel版本为3.x,其依赖的Spring Framework为5.x,与Spring Boot 3.x依赖的Spring Framework 6.x冲突,导致事务相关类无法正常加载。
  2. 依赖树异常:虽然spring-boot-starter-web依赖spring-tx,但可能存在依赖冲突导致spring-tx被排除,或版本不符合Spring Boot 3.x要求。
  3. 自动配置触发扫描:即使未使用事务,Spring Boot自动配置仍会尝试创建事务相关Bean,若项目或依赖库中存在自定义的TransactionManagerCustomizer实现,引用了旧版本Spring事务类,会触发类型检查导致类找不到。

解决方案

1. 升级Camel至兼容版本

Spring Boot 3.2.0对应的Camel兼容版本为4.0.x及以上,修改pom.xml中的${camel.version}为兼容版本(例如4.3.0):

<properties>
    <camel.version>4.3.0</camel.version>
</properties>

2. 锁定Spring Framework版本

在pom.xml的dependencyManagement中引入Spring BOM,强制统一所有Spring相关依赖版本:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>6.1.1</version> <!-- 与Spring Boot 3.2.0匹配的版本 -->
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

3. 确认并添加spring-tx依赖

执行mvn dependency:tree查看依赖树,搜索spring-tx确认其版本为6.x且未被排除。若缺失,手动添加:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
</dependency>

4. 禁用事务自动配置

若项目完全不需要事务相关功能,可在启动类中排除事务自动配置类:

@SpringBootApplication(exclude = {TransactionManagerCustomizationAutoConfiguration.class})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

验证步骤

  1. 执行mvn clean install清理缓存并重新构建项目
  2. 启动项目,检查异常是否消失

内容的提问来源于stack exchange,提问作者gigapogg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 22:47:33