[Answer]-"no feign client for loadbalancing defined. did you forget to include spring-cloud-starter-loadbalancer?"


"java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-netflix-ribbon?"

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:

  1. Check if you have included the spring-cloud-starter-netflix-ribbon dependency in your project. This dependency provides the necessary Feign client for load balancing.
  2. If you are using Maven, ensure that the dependency is added to your 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>