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

Spring Boot 2.5.4搭配Spring Cloud 2020.0.3启动报错如何解决

问题原因
  • 核心错误触发原因是org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata类缺失,该类在Spring Boot 2.4及以上版本已经被官方移除。
  • 你项目中单独指定了spring-cloud-starter-netflix-hystrix的版本为2.2.9.RELEASE,这个版本依赖的是旧版Spring Cloud上下文组件(spring-cloud-context),旧版组件仍在调用已被移除的ConfigurationBeanFactoryMetadata类,导致类加载失败。
  • Spring Cloud 2020.0.x(代号Ilford)版本已经正式移除了所有处于停止维护状态的Netflix OSS组件,包括Hystrix,你手动指定Hystrix版本的操作跳过了Spring Cloud依赖版本的兼容性管理,最终引发版本冲突。
  • 项目构建时不会触发Spring自动配置的类加载逻辑,所以不会报编译错误,只有服务启动时自动配置加载对应Bean才会触发类找不到的异常。
解决方案

方案1:替换Hystrix为官方推荐替代组件(推荐)

Spring官方已经推荐使用Resilience4j替代停止维护的Hystrix,操作如下:

  • 移除pom.xml中现有的spring-cloud-starter-netflix-hystrix依赖
  • 引入Resilience4j对应的Spring Cloud适配依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
  • 按照Resilience4j的使用规范调整原有熔断相关代码即可,兼容性和后续维护性更有保障。

方案2:强制兼容旧版Hystrix(不推荐,仅临时过渡使用)

如果暂时没有精力替换Hystrix,可以通过排除冲突依赖+引入兼容包的方式临时解决:

  • 给Hystrix依赖排除旧版的spring-cloud-context依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    <version>${spring-cloud-starter-netflix-hystrix.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-context</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • 额外引入兼容Spring Boot 2.5.x版本的spring-cloud-context依赖:
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-context</artifactId>
    <version>3.0.5</version>
</dependency>

注意:该方案仅为临时过渡,后续仍建议替换为Resilience4j,避免后续版本升级再出现兼容性问题。

内容的提问来源于stack exchange,提问作者Sashank Sekhar Singh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 23:57:02