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

Spring Cloud FeignClient未读取配置的服务器列表问题求助

问题解决:FeignClient无法读取服务器列表配置

问题原因

你使用的Spring Cloud 2021.0.5(Ilford版本)已经弃用了Ribbon,默认采用Spring Cloud LoadBalancer作为负载均衡组件,因此原来基于Ribbon的xxx.ribbon.listOfServers配置不再生效,导致FeignClient找不到配置的服务地址,转而使用默认的http://服务名/格式请求。

解决方案

方案一:使用Spring Cloud LoadBalancer配置(推荐)

这是当前版本的标准做法,步骤如下:

  1. 确保项目中包含Spring Cloud LoadBalancer依赖(若spring-cloud-starter-openfeign未自动引入,需手动添加):
    implementation 'org.springframework.cloud:spring-cloud-starter-loadbalancer'
    
  2. 在application.properties中替换原Ribbon配置为以下内容:
    # 配置MY-SERVICE的服务实例地址
    spring.cloud.discovery.client.simple.instances.MY-SERVICE[0].uri=https://my-service-api.prod.cloud.net
    
    若有多个实例,继续添加[1]、[2]格式的配置即可。

方案二:强制启用Ribbon(不推荐,已弃用)

如果需要继续沿用Ribbon配置,需手动引入依赖并启用:

  1. 添加Ribbon依赖:
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-ribbon'
    
  2. 在配置文件中启用Ribbon作为负载均衡器:
    spring.cloud.loadbalancer.ribbon.enabled=true
    
    此时原MY-SERVICE.ribbon.listOfServers=https://my-service-api.prod.cloud.net配置会生效。

验证

修改完成后重启服务,FeignClient将读取配置的服务地址发起请求,不再使用默认的http://MY-SERVICE/格式。

内容的提问来源于stack exchange,提问作者Pramod H G

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 08:05:14