SpringCloud学习——负载均衡Ribbon

两个常见错误

自定义负载均衡报错

Invalid bean definition with name 'myRule' defined in com.atguigu.MyLb.MySelfRule: Bean name derived from @Bean method 'myRule' clashes with bean name for containing configuration class; please make those names unique!

这是因为Bean的名称不唯一导致的错误,修改名称即可解决

No instances available for SPRINGCLOUD-PROVIDER-DEPT

这个错误是在Ribbon客户端启动的时候调用出错,我说下自己的原因,从开始项目,我使用的是SpringCloud的2020.0.4这个版本,然后其对应的Netfix的组件都是3.0.3,这个可以在Spring的官网查询到

然后在集成Ribbon的时候报错,我之前使用的Eureka的版本是如下pom文件

   <!--服务端-->
   <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>3.0.3</version>
   </dependency>
   <!--客户端-->
   <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>3.0.3</version>
   </dependency>
   <!--Ribbon-->
   <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
            <version>2.2.6.RELEASE</version>
    </dependency>

然后启动报错No instances available for SPRINGCLOUD-PROVIDER-DEPT,网上有很多的解决方法。一一尝试都未能解决我的问题,如

 将这个改成小写字母,或者是去掉下划线,但是尝试过后还是不能解决问题,还有就是去掉Ribbon的依赖,但是去掉这个依赖之后Ribbon自定义负载均衡算法就无法使用。查询很多帖子都是说spring-cloud-starter-netflix-eureka-client集成了Ribbon但是确实是无法使用,后经查询Maven仓库才知道

spring-cloud-starter-netflix-eureka-client 3.0以上的版本集成的是 spring-cloud-starter-loadbalancer 所以最终的解决方案就是降低SpringCloud的版本,由2020.0.4降低到Hoxton.SR12,需要注意的是,SpringBoot的版本也需要降低到2.3.12.RELEASE。

最终问题得以解决

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值