springcloud引入openfeign依赖后,启动项目报错:
Unsatisfied dependency expressed through field 'vodClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.atguigu.eduservice.client.VodClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
关键句:
Did you forget to include spring-cloud-starter-loadbalancer?
有人问我,R老师发生甚么事了?
我一看,噢,原来是昨天,我把springcloud升级到了最新版本
我大意了啊,没有闪。
查阅一番后发现:
SpringCloud Feign在Hoxton.M2 RELEASED版本之后不再使用Ribbon,而是使用spring-cloud-loadbalancer,所以不引入spring-cloud-loadbalancer会报错
解决方法:
加入spring-cloud-loadbalancer依赖,并且在nacos中排除ribbon依赖,不然loadbalancer无效
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.5.RELEASE</version> <exclusions> <exclusion> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-ribbon</artifactId> </exclusion> </exclusions> </dependency> <!-- spring-cloud-loadbalancer --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>
或是降低SpringCloud、SpringBoot版本
- Post link: http://example.com/2021/05/22/SpringCloud-OpenFeign%E5%BC%95%E5%85%A5%E5%90%8E%E6%8A%A5%E9%94%99/
- Copyright Notice: All articles in this blog are licensed under unless otherwise stated.