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

Spring版本兼容问题:TelemetrySender与ResponseEntity方法调用失败求助

解决Spring应用启动的版本冲突问题

问题详情

应用启动失败,核心错误为方法不存在:

尝试调用一个不存在的方法,调用发起位置:

com.microsoft.azure.telemetry.TelemetrySender.sendTelemetryData(TelemetrySender.java:58)

不存在的方法为:

'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()'

冲突版本信息

  • 调用方类com.microsoft.azure.telemetry.TelemetrySender加载路径:
    jar:file:/home/spiritbear/.m2/repository/com/microsoft/azure/azure-spring-boot/2.2.1/azure-spring-boot-2.2.1.jar!/com/microsoft/azure/telemetry/TelemetrySender.class
    
  • 被调用方类org.springframework.http.ResponseEntity加载路径:
    jar:file:/home/spiritbear/.m2/repository/org/springframework/spring-web/6.0.3/spring-web-6.0.3.jar!/org/springframework/http/ResponseEntity.class
    

冲突原因

Spring 6.x(对应Spring Boot 3.x)对ResponseEntity类做了API变更:getStatusCode()方法的返回值从HttpStatus改为HttpStatusCode。而你使用的azure-spring-boot-2.2.1是基于Spring Boot 2.x开发的,依赖旧版的getStatusCode()方法签名,因此与Spring 6.x的spring-web jar包出现兼容性冲突。

解决方案

方案1:升级Azure Spring Boot Starter到兼容版本

Azure Spring Boot Starter 4.x及以上版本适配Spring Boot 3.x(Spring 6.x),更新pom.xml中的依赖版本:

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-spring-boot</artifactId>
    <version>4.13.0</version> <!-- 可选择最新稳定兼容版 -->
</dependency>

方案2:降级Spring Boot到2.x版本

若暂时无法升级Azure Starter,可将Spring Boot版本降级到2.x(对应Spring 5.x),确保与azure-spring-boot-2.2.1兼容:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.14</version> <!-- Spring Boot 2.x最新稳定版 -->
    <relativePath/>
</parent>

方案3:排除冲突依赖(不推荐)

若必须保留现有版本组合,可尝试排除azure-spring-boot中的旧版spring-web依赖,但可能引发其他兼容性问题,需谨慎测试:

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-spring-boot</artifactId>
    <version>2.2.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 12:46:14