To resolve the error "java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netflix-ribbon?" you can follow these steps:
spring-cloud-starter-netflix-ribbon
dependency in your project. This dependency provides the necessary Feign client for load balancing.pom.xml
file:<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>{version}</version>
</dependency>
If you are using Gradle, add the following dependency to your build.gradle
file:
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-ribbon:{version}'
Ensure that you replace {version}
with the version of Spring Cloud you are using.
Replacing path
with url
in the Feign client class, along with @ImportAutoConfiguration({FeignAutoConfiguration.class})
in the main class, may work.
Please share your pom.xml
. It appears that you don't have the spring-cloud-starter-loadbalancer
dependency in your project.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>2.4.4</version>
</dependency>
Change the FeignClient
class to:
@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class FeignClientApplication {
public static void main(String[] args) {
SpringApplication.run(FeignClient.class, args);
}
}
The following Maven dependency helped me solve this issue:
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.4.1</version>
</dependency>