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

SpringBoot 2.0.2.RELEASE启动Jetty容器时出现NoSuchMethodError求助

解决SpringBoot + Jetty WAR启动时的NoSuchMethodError问题

嘿,我一眼就从你的异常日志里揪出问题根源了——这是Spring版本冲突导致的!

你看日志里这关键的一行:

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]

虽然你说spring-boot-starter-jetty引入的是Spring 5.0.6.RELEASE,但运行时却加载了旧版本的spring-context-4.3.12.RELEASE。而org.springframework.web.servlet.handler.AbstractHandlerMapping.obtainApplicationContext()这个方法是Spring 5.x才新增的,4.x里根本没有,所以才会抛出NoSuchMethodError。

给你几个落地的解决步骤:

  • 第一步:排查依赖树,找出冲突来源
    执行Gradle命令查看完整依赖树,定位哪个第三方依赖偷偷引入了Spring 4.x:

    # Linux/Mac环境
    ./gradlew dependencies
    
    # Windows环境
    gradlew.bat dependencies
    

    在输出里搜索spring-context,看除了Spring Boot管理的5.0.6.RELEASE外,还有哪个依赖带出了4.3.12.RELEASE版本。

  • 第二步:排除冲突的旧版本依赖
    找到问题依赖后,在Gradle的dependencies块里排除它引入的旧版Spring组件。比如假设是some-old-lib导致的:

    implementation('com.example:some-old-lib:1.0.0') {
        exclude group: 'org.springframework', module: 'spring-context'
        // 如果还有其他冲突的Spring模块(比如spring-core),也一起排除
        exclude group: 'org.springframework', module: 'spring-core'
    }
    
  • 第三步:强制统一Spring版本(可选但推荐)
    为了彻底避免版本混乱,你可以通过Spring Boot的依赖管理平台强制所有Spring相关依赖使用指定版本:

    plugins {
        id 'org.springframework.boot' version '2.0.2.RELEASE'
        id 'war'
    }
    
    dependencies {
        implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
        implementation 'org.springframework.boot:spring-boot-starter-jetty'
        // 其他业务依赖...
    }
    

最后别忘了重新打包后,检查WAR包的WEB-INF/lib目录,确保所有Spring相关Jar包都是5.0.6.RELEASE版本,没有混入4.x的旧包~

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:33:31