SpringCloud OpenFeign报错
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
问题原因
使用Spring Initializr初始化项目引入了openfeign,没有在意版本。直到运行项目进行远程调用时报错.
由于Spring Cloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错.
解决方法:
加入spring-cloud-loadbalancer依赖 并且在nacos中排除ribbon依赖,不然loadbalancer无效
- 排除ribbon依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<groupId>com.netflix.ribbon</groupId>
<artifactId>ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
- 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
如果还是没有解决,请去官方查阅框架对应的版本,实在不行将spring boot和spring cloud的版本全部降下来。
原文链接:https://blog.csdn.net/qq_43788878/article/details/115764008
标签:Feign,openfeign,No,spring,ribbon,starter,cloud,loadbalancer From: https://www.cnblogs.com/zhouXX/p/16756797.html