spring cloud整合feign和nacos报错:No Feign Client for loadBalancing defined. Did you forget to include

SpringCloud使用 Nacos做注册中心 客户端启动报错java.lang.IllegalArgumentException: no server available的解决方案 困扰我很多天的问题了,报错 no server available Error watching Nacos Service change java.lang.IllegalArgumentException: no server available at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:354) ~[nacos-client-1.0.0.jar:na] at com.alibab 阅读详情
AI摘要

本文解决了使用最新版本Nacos和Feign时出现的负载均衡问题。通过逐步尝试引入Eureka依赖、降低Spring Cloud版本及添加Ribbon等方法,最终发现需引入spring-cloud-loadbalancer并排除Nacos中的Ribbon依赖。

问题描述

最近在使用最新版本的nacos和feign的过程中,启动时遇到一个错误:

Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

在这里插入图片描述
百思不得其解,之前的spring cloud版本没有遇到这样的问题。花了将近几个小时,终于解决,记录一下,希望能给大家带来一点帮助。

项目环境

项目中的父pom文件版本依赖管理如下:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
    </parent>
     <properties>
        <spring-cloud.version>2020.0.2</spring-cloud.version>
    </properties>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

用的是最新版本的springboot 和springcloud,然后在子项目中,我用到了feign和nacos,依赖如下:

 <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>
        
         <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
 </dependencies>

解决方案

1、引入eureka依赖——无效

第一时间想到的,spring cloud和springboot版本不兼容。查看spring cloud官网,发现spring boot版本号和spring cloud版本号可以对应:
在这里插入图片描述
说明项目是没问题的,就上网查找了一下,结果参考了这两位仁兄说的:
在这里插入图片描述
在这里插入图片描述

在项目中加入eureka依赖:

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

再次启动,报错:

Field autoServiceRegistration in org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration required a single bean, but 2 were found:
	- nacosAutoServiceRegistration: defined by method 'nacosAutoServiceRegistration' in class path resource [com/alibaba/cloud/nacos/registry/NacosServiceRegistryAutoConfiguration.class]
	- eurekaAutoServiceRegistration: defined by method 'eurekaAutoServiceRegistration' in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


在这里插入图片描述
这是因为项目中已经用到了nacos,再次引入eureka,会造成有两个注册中心的问题,说明这种解决方案无效。

2、降低spring cloud版本——无效

既然之前的版本没问题,那我就降级回去不就完事了,于是乎,我把项目的父pom中spring cloud版本降级到Hoxton SR1,spring boot版本也随之降级到2.2.1,即:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
    </parent>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


maven clean后再次启动,仍然报错:

在这里插入图片描述
错误信息:


Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:333) ~[spring-cloud-openfeign-core-3.0.2.jar:3.0.2]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:360) ~[spring-cloud-openfeign-core-3.0.2.jar:3.0.2]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:339) ~[spring-cloud-openfeign-core-3.0.2.jar:3.0.2]
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:230) ~[spring-cloud-openfeign-core-3.0.2.jar:3.0.2]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1231) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.5.jar:5.3.5]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.5.jar:5.3.5]
	... 34 common frames omitted

这次的错误信息跟第一次一样,可见降低版本这事已经行不通了,于是我复原了父pom。

3、添加ribbon——无效

在stackoverflow上看到了这两种解决方案:
在这里插入图片描述
因为不想在feign上加url,显得比较麻烦,于是我选择了第二种方案,加ribbon并配置了相关属性,启动还是报错:

Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

但是其中的第一种方案,我还是有点感兴趣,于是就根据第一种方案中的关键字spring-cloud-loadbalancer,搜索了一下。

4、加入spring-cloud-loadbalancer并在nacos中排除ribbon依赖——问题解决

继续搜索,发现如下结果:
在这里插入图片描述
根据这位大佬的说法,这是因为:

由于SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错
解决方法
加入spring-cloud-loadbalancer依赖 并且在nacos中排除ribbon依赖,不然loadbalancer无效

问题突然有了点头目,于是乎,加入如下依赖:

//我是在这引入了spring-cloud-starter-alibaba-nacos-discovery
<dependency>
    <groupId>com.oyz.gulimall</groupId>
    <artifactId>gulimall-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </exclusion>
    </exclusions>
</dependency>
//加入spring-cloud-loadbalancer依赖


<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>

之后,再次启动项目:
在这里插入图片描述
问题完美解决,还是得关注问题报错点:Did you forget to include spring-cloud-starter-loadbalancer,一开始没有注意到这个点,浪费了许多时间。

参考链接

  1. Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined
  2. stackoverflow
  3. SpringCloud OpenFeign报错
  4. No Feign Client for loadBalancing defined
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbala报错 启动程序,出现下面错误 No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer? 报错原因:项目中缺少 spring-cloud-starter-loadbalancer 依赖项 解决方案:pom 中加入以下依赖项 <dependency> <groupId>org.springframework.cloud</groupId& 阅读详情

相关推荐

No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc

这是因为由于SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错。Hoxton.M2 RELEASED版本后,不在使用Ribbon而是采用spring-cloud-loadbalancer,依赖关系如下。如果出现如下报错,可能是版本问题导致的,这个报错是说缺少spring-cloud-starter-loadbalancer依赖。

程序员劝退师的博客 4286

已解决集成feign报错:No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-start

在使用最新版本springboot3.0和spring-cloud2022.0.1中引入feignclient时出现了以下错误,无法被创建 问题原因 SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用ribbon而是使用spring-cloud-loadbalancer,所以在不引入spring-cloud-loadbalancer情况下会报错 所以会出现以下错误:

weixin_60223449的博客 6373

Cherry Studio部署MCP服务报错全记录:从零解决‘Connection closed‘问题

本文详细记录了在Cherry Studio中部署MCP服务时遇到‘Connection closed’报错的完整排查与解决过程。文章从环境依赖(UV、Bun)的安装验证、绝对路径配置、网络镜像源设置,到服务端手动调试与Cherry Studio配置检查,提供了一套系统性的解决方案,帮助开发者彻底解决此类连接问题。

g9h0i1的博客 761

解决微服务No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netfl

没有loadBalancing定义的feign客户端。忘了加入 spring-cloud-starter-loadbalancer或spring-cloud-starter-netflix-ribbon 了吗?不用写版本号,跟随 spring cloud 版本即可。

hkl_Forever的博客 5114

图解B树的原理及操作

本文主要参考:https://blog.csdn.net/shenchaohao12321/article/details/83243314 1. B树 1.1 B树的定义 B树也称B-树,它是一颗多路平衡查找树。我们描述一颗B树时需要指定它的阶数,阶数表示了一个结点最多有多少个孩子结点,一般用字母m表示阶数。当m取2时,就是我们常见的二叉搜索树。 一颗m阶的B树定义如下: 1)每个结点最多有m-1个关键字。 2)根结点最少可以只有1个关键字。 3)非根结点至少有Math.ceil(m/2)-

jinking01的专栏 3万+

机械臂抓取前言

机械臂相关的笔记

weixin_64037619的博客 3908

已解决集成feign报错:No Feign Client for loadBalancing defined. Did you forget to include

问题描述: 最近在使用最新版本的nacos和feign的过程中,启动时遇到一个错误:

欢迎来到 程序猿 的博客 2万+

工业相机的检测原理课件(建议收藏)

本课件为各位工程师详细介绍了工业相机的视觉检测原理 ,旨在为工程师调试工业相机的视觉检测原理时提供理论性指导。

Bamboo265925的博客 498

微服务启动报错:No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-lo

微服务启动报错:No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

dd2016124的博客 3207

谁在 SAP 系统里说了算:事务码 SCC4 与 SE06 的分工、优先级与实战管控

SAP系统通过SE06和SCC4两套机制控制变更权限:SE06作为系统级"总闸"管理跨Client对象修改,SCC4作为Client级"分闸"控制Client内配置变更。两者存在明确优先级,SE06的全局设置优先于SCC4。当SE06设为"不可修改"时,即使SCC4开放也无法更改跨Client对象。实际项目中需同时检查两处设置,并遵循"最小开放"原则进行变更管理。这种分层设计既满足日常维护需求,又能实现严格的变更管控。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 228

Flink CDC 中 StartupOptions 模式详解

Flink CDC 的 StartupOptions 模式用于指定作业启动时从源数据读取数据的起始位置,不同的模式适用于不同的业务场景,可满足多样化的数据处理需求,主要有 Initial 模式、Earliest 模式、Latest 模式、SpecificOffset 模式和 Timestamp 模式。

RodJohnsonDoctor的专栏 849

Java:SpringCloud程序使用Feign时报错:No Feign Client for loadBalancing defined. Did you forget to include ..

Java:SpringCloud程序使用Feign时报错:lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

weixin_52116015的博客 645

手把手保姆级|Python爬取微信公众号文章完整版,反反爬策略拉满,附可运行完整代码(永久可用)

做Python爬虫的朋友都知道,爬取微信公众号文章 绝对是爬虫领域的「香饽饽」也是「硬骨头」。一方面,微信公众号的文章是极具价值的数据源:不管是自媒体从业者做竞品分析、新媒体运营者整理干货、还是个人学习收集资料,都需要批量爬取公众号文章;另一方面,微信的反爬机制堪称全网最严苛之一 ——腾讯对微信生态的风控做到了极致,动态渲染页面、高频IP封禁、Cookie短时效失效、请求头严格校验、自动化工具秒识别、频繁请求直接拉黑,这些反爬手段让90%的爬虫新手望而却步:要么爬了几篇就被封IP,要么Cookie失效爬取中

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2624

SpringCloud整合Feign和Nacos报错:No Feign Client for loadBalancing defined. Did you forget to include?

在做谷粒商城项目的时候,使用的版本如下 spring-cloud.version:2021.0.3 spring-boot-starter-parent:2.6.8 spring-cloud-alibaba-dependencies:2.1.0.RELEASE 和视频版本有所出入,导致SpringCloud整合Feign和Nacos报错SpringCloud整合Feign和Nacos报错:No Feign Client for loadBalancing defined. Did you forget to

一生烟雨的博客 480

nuScenes数据集详细介绍

nuScenes网上介绍资料较多,但是大部分仅仅是对官网的翻译,缺乏各个文件的内在联系介绍。例如,nuScenes激光雷达的数据格式,点云包含哪几种属性。再比如,sample文件夹和sweeps文件夹下的文件关系,以及是如何在相关json文件中体现的。本文将详细介绍nuScenes数据集的各个部分。

叶子的博客 1万+

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

No Feign Client for loadBalancing defined. Didyou forget to include spring-cloud-starter-loadbalance

Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer? OpenFeign报错 No Feign Client for loadBalancing defined. D

weixin_44524763的博客 4573

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[gulimall报错]No Feign Client for loadBalancing defined. Did you forget to include..

今天在写gulimall商城的时候,出现以下错误 No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer? 问题分析: 我英语也不太好,我们分析错误时,只需要抓住关键字即可,我是在使用openfeign的时候出现错误,上面错误有一个关键字,就是loadBalancing(负载均衡),后来我去查了下官网: 由于Spring Cloud Feign在Hoxton

qq_44250569的博客 552

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

已解决 No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadba

已解决 No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer? 出现这个问题是没有loadbalanc 但是nacos中ribbon会造成loadbalanc包失效 由于SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-.

weixin_48776118的博客 757

微服务启动报:No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loa

微服务启动报错: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

shs1124的博客 824

Fegin远程调用报错:No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starte

刚才学习guilimall的时候使用openfeign进行远程调用的时候,出现了以下错误: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberController': Unsatisfied dependency expressed through field 'couponFeignService'; nested exception is org.s

m0_58827582的博客 430
上一篇: 【微服务入门】分布式事务详解及seata的使用
下一篇: Java15来了!!!一文详解JDK15新特性
codu4u1314
博客等级 码龄7年 29粉丝 19原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值