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

Java8升级Java17+Spring3后异步调用OpenFeign客户端报错

Java 8迁移至Java 17+Spring 3后Feign异步调用报错处理

报错信息

{
  "code": "SI-SERVICE-ERROR-000500",
  "message": "org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [org.springframework.cloud.loadbalancer.annotation.LoadBalancerClientConfiguration]
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.condition.OnPropertyCondition
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
}

相关代码

Feign客户端

@Service
@FeignClient(name = "si-booking-service", path = "/si-booking-service/bookings")
public interface SIBookingServiceClient {...}

主启动类

@EnableFeignClients
@EnableDiscoveryClient
public class MainApplication {..}

问题原因

核心是Spring Cloud版本与Spring Boot 3.x不兼容:

  • OnPropertyCondition类在Spring Boot 3.x中已被移除或重构,旧版本Spring Cloud LoadBalancer仍在尝试加载该类。
  • Spring Boot 3.x要求搭配Spring Cloud 2022.0.x(代号Kilburn)及以上版本,低版本Spring Cloud组件会触发此类依赖冲突。

解决方案

  1. 对齐版本依赖
    确保Spring Cloud版本与Spring Boot 3.x匹配,推荐使用Spring Cloud 2022.0.x系列。以Maven为例,在pom.xml中配置:

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-dependencies</artifactId>
          <version>2022.0.4</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
    
  2. 清理Feign客户端注解
    @FeignClient会自动将接口注册为Spring Bean,无需额外添加@Service,重复注解可能引发Bean注册冲突,建议移除@Service:

    @FeignClient(name = "si-booking-service", path = "/si-booking-service/bookings")
    public interface SIBookingServiceClient {...}
    
  3. 更新LoadBalancer依赖
    确保spring-cloud-starter-loadbalancer依赖版本与Spring Cloud版本一致,避免引入过时包。

  4. 移除过时配置
    若有自定义LoadBalancer配置类,检查是否引用了Spring Boot 3.x中废弃的类或API,替换为新版本对应实现。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 07:05:11