项目场景:
在做谷粒商城项目的时候,使用的版本如下
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 include?
原因分析:
由于SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错.解决方法加入spring-cloud-loadbalancer依赖 并且在nacos中排除ribbon依赖,不然loadbalancer无效
解决方案:
spring-cloud-loadbalancer依赖 并且在nacos中排除ribbon依赖
<dependency>
<groupId>com.vector.gulimail</groupId>
<artifactId>gulimail-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--在nacos中排除ribbon依赖-->
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--加入spring-cloud-loadbalancer依赖 解决Did you forget to include spring-cloud-starter-loadbalancer-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>