When learning how to integrate spring cloud with Alibaba, we encountered an openfeign call error
Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?
at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:309) ~[spring-cloud-openfeign-core-3.0.0.jar:3.0.0]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:335) ~[spring-cloud-openfeign-core-3.0.0.jar:3.0.0]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:315) ~[spring-cloud-openfeign-core-3.0.0.jar:3.0.0]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169) ~[spring-beans-5.3.3.jar:5.3.3]
... 47 common frames omitted
Baidu found that openfeign 3.0.0 built in spring cloud 2020.0.0 conflicts with Nacos framework of spring cloud Alibaba.
Here are two solutions
Methond 1
First add the loadbalancer dependency in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
Because nacos dependencies containing ribbon dependencies will cause loadbalancer to be invalid, you need to exclude the ribbon dependencies from nacos dependencies.
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<groupId>org.springframework.cloud</groupId>
</exclusion>
</exclusions>
</dependency>
Method 2
<!-- spring cloud 2020.0.0built-in openfeign3.0.0 and spring cloud alibaba framework nacos, seata conflict temporary solution - >
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.6.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
Read More:
- Gateway Error: Cannot resolve org.springframework.cloud:spring-cloud-starter-gateway:unknown
- [Solved] Spring cloud introduces zuul dependency error
- How to Solve Spring Cloud Error context has been closed already
- Spring cloud Eureka error creating bean with name
- [Solved] Spring cloud config server can’t parse the YML file of the remote warehouse, and it will also report an error
- [Solved] Spring cloud load balancing, error: no instances available for localhost
- [Solved] Failed to bind properties under ‘spring.datasource.type‘ to java.lang.Class<javax.sql.DataSource>
- cloud.callFunction:fail Error:wx is not defined [How to Solve]
- How to Solve AOP error in Spring
- Tencent cloud container easyexcel export excel error NoClassDefFoundError: could not initialize class sun.awt.x11fontmanager
- [neo4j] error report when visiting neo4j in spring boot project
- Two implementation methods of spring boot scan mapper interface class
- How to Solve Spring MVC upload file error
- How to Solve the jump error after Spring Security Login
- When integrating redis with SSM framework, error creating bean with name ‘rediscontentserviceimpl’ defined in file
- [How to Fix] Spring boot startup error: could not resolve placeholder
- SpringCloud: gateway module startup error [How to Solve]
- Spring deployment error: Could not open ServletContext resource [/db.properties]
- [Solved] Logging system failed to initialize using configuration from ‘classpathlogbacklogback-spring.xml‘
- Spring Connect Redis Error: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: MOVED 12910 172.16.4.99:6379