【错误解决】Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined.
序:最近使用spring cloud alibaba遇了几个大坑,记录一下1. 错误描述今天用openfeign,报了一个就是标题所示这个错误Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-sta
序:最近使用spring cloud alibaba遇了几个大坑,记录一下
1. 错误描述
今天用openfeign,报了一个就是标题所示这个错误
Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
翻了一小时资料,发现是由于SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错,于是看到希望的我加了一下如下依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
项目跑起来了,正当我以为事情完美解决时,生活又给我当头一棒,报了500错,到后台一看,出了下面提示
java.lang.AbstractMethodError: org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(Ljava/lang/String;Lorg/springframework/cloud/client/loadbalancer/Request;)Lorg/springframework/cloud/client/ServiceInstance;
能咋办,继续翻资料呗,面向百度编程(不是
发现是由于导入 spring-cloud-loadbalancer后nacos中 spring-cloud-starter-netflix-ribbon会与它冲突,造成loadbalanc包失效
2. 错误解决
完美解决方式:将spring-cloud-starter-alibaba-nacos-discovery中spring-cloud-starter-netflix-ribbon排除,然后再引入spring-cloud-loadbalancer
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
到此,问题完美解决,花了一下午,版本太高了就是会出现这种奇奇怪怪的bug,但是学习新知识还是不错滴(奇怪的知识增加了.JPG)
更多推荐
所有评论(0)