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

部署至Tomcat时Spring AOP启动异常求助

解决Spring AOP启动时的NoSuchMethodError(旧版本依赖冲突)

问题根源

你遇到的NoSuchMethodError是因为项目加载了spring-aop-2.5.6.SEC03这个旧版本,而org.springframework.core.CollectionFactory.createConcurrentMapIfPossible方法是Spring 3.0及以后版本才新增的,旧版本不存在该方法,导致Bean初始化失败。

解决方案步骤

1. 定位旧版本依赖来源

执行Maven命令生成完整依赖树,找出哪个依赖间接引入了旧版spring-aop:

mvn dependency:tree

在输出结果中搜索spring-aop,找到标注版本为2.5.6.SEC03的条目,查看它的父依赖(即[INFO] +-层级的上层依赖)。

2. 统一Spring依赖版本

在POM的<dependencyManagement>节点中声明所有Spring模块的统一版本,确保spring-aop与spring-core等核心组件版本一致(选择适配Tomcat 8.5的Spring版本,比如4.3.x系列):

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.3.29.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.3.29.RELEASE</version>
        </dependency>
        <!-- 补充项目中用到的其他Spring模块,如spring-context、spring-beans等,统一版本 -->
    </dependencies>
</dependencyManagement>

3. 排除旧版本依赖

针对步骤1中找到的引入旧版spring-aop的父依赖,在POM的对应<dependency>中添加排除规则:

<dependency>
    <groupId>父依赖的groupId</groupId>
    <artifactId>父依赖的artifactId</artifactId>
    <version>父依赖版本</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </exclusion>
        <!-- 若该父依赖还引入了其他旧版Spring模块,一并排除 -->
    </exclusions>
</dependency>

4. 清理并验证项目

  • 执行Maven清理构建命令,确保依赖更新:
    mvn clean install
    
  • 在IntelliJ中刷新Maven依赖(点击右侧Maven面板的刷新图标);
  • 清理Tomcat缓存:删除Tomcat安装目录下的webapps和work文件夹,避免旧Jar包残留。

额外建议

Maven 4目前处于预览阶段,存在未知兼容性问题,建议切换到稳定的Maven 3.8.x版本,降低构建风险。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 17:05:20