No Feign Client for loadBalancing defined. Didyou forget to include spring-cloud-starter-loadbalance

拓拔野
2023-12-01

Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

OpenFeign报错

No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

Spring Cloud版本 2020.0.3
Spring Boot版本 2.4.6

原因是因为SpringCloud Feign在Hoxton.M2 RELEASED版本之后抛弃了Ribbon,使用了spring-cloud-loadbalancer,所以我们这里还需要引入spring-cloud-loadbalancer的依赖,否则就会报错

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-loadbalancer</artifactId>
        </dependency>

同时nacos也要排除掉ribbo

 <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-netflix-ribbon</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

到这里问题解决

 类似资料: