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

Spring Boot 3.0.2升级后出现NoSuchMethodError问题求助

Spring Boot 3.0.2升级后NoSuchMethodError问题解决

错误原因

这个NoSuchMethodError的核心冲突在于:

  • 你使用的spring-security-oauth2-2.0.17.RELEASE是过时的老旧版本,它依赖的Spring Web方法签名和Spring Boot 3.0.x配套的Spring Web 6.x不兼容。
  • Spring 6.x中ClientHttpResponse.getStatusCode()的返回值已从org.springframework.http.HttpStatus改为org.springframework.http.HttpStatusCode,但旧版OAuth2ErrorHandler仍在调用旧方法签名,导致找不到方法。

解决步骤

  • 移除旧依赖:项目中直接或间接引入的spring-security-oauth2(2.x版本)必须移除,这个模块在Spring Security 5.x之后就被拆分,Spring Boot 3.x不再兼容它。
  • 引入新版OAuth2客户端依赖:使用Spring Boot官方提供的starter来获取兼容的OAuth2客户端组件:
    <!-- Maven 配置 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-oauth2-client</artifactId>
    </dependency>
    
    或者Gradle:
    // Gradle 配置
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    
  • 排查依赖冲突:用依赖分析工具检查是否有其他依赖间接引入了旧版spring-security-oauth2:
    • Maven执行命令:mvn dependency:tree
    • Gradle执行命令:./gradlew dependencies
      找到后通过<exclusions>(Maven)或exclude(Gradle)排除旧依赖。
  • 调整代码适配新版:如果之前使用了旧的OAuth2RestTemplate,需要替换为Spring Security 6.x的推荐方案,比如用OAuth2AuthorizedClientManager配合RestTemplate,或者使用WebClient结合OAuth2支持。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 08:11:30