Debug - Feign: Did you forget to include spring-cloud-starter-loadbalancer

一、错误信息

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

 

二、根本原因

由于SpringCloud Feign在Hoxton.M2 版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错

 

三、解决方案

3.1 加入loadbalancer依赖,但需要exclude ribbon(实践可行)

此方案下的:

  • springboot版本: 2.5.3
  • springcloud版本: 2020.0.3

就算加入load balancer,但是依然会报同样的错。原因是:nacos中ribbon会造成loadbalanc包失效

所以要先exclude ribbon:

<!-- 服务注册与发现 -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>2.2.0.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

 

再引入load balancer:

<!--load balancer-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-loadbalancer</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

 

3.2 SpringCloud, SpringBoot 降版本(实践出错)

修改它的pom文件中spring cloud的版本

Debug - Feign: Did you forget to include spring-cloud-starter-loadbalancer

修改了下spring boot版本

Debug - Feign: Did you forget to include spring-cloud-starter-loadbalancer

参考:https://www.cnblogs.com/npeng/p/14272634.html

 

上一篇:内含福利|阿里云数据库再获学术顶会认可,一文全览VLDB最新亮点


下一篇:治愈英文:I Did My Best Today(中英文)