FeignContext - NoSuchBeanDefinitionException

FeignContext NoSuchBeanDefinitionException: Causes and Fixes

When using Spring Cloud OpenFeign, you may encounter a NoSuchBeanDefinitionException stating that no bean of type FeignContext is available. This usually means Feign’s Spring configuration has not been loaded, or that the application’s dependencies and configuration are inconsistent.

1. Check Your OpenFeign Dependency

Make sure the OpenFeign starter is included in your project. With Maven, add the Spring Cloud starter and manage its version through a Spring Cloud release-train BOM compatible with your Spring Boot version:

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

For Gradle:

implementation("org.springframework.cloud:spring-cloud-starter-openfeign")

Do not choose Spring Cloud and Spring Boot versions independently. Use the compatibility guidance for your Spring Boot release, and avoid adding conflicting versions of the underlying Feign libraries unless you have a specific reason.

2. Enable Feign Client Scanning

Add @EnableFeignClients to a configuration class that Spring scans, commonly the main application class:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

If your Feign client interfaces are outside the application class’s component-scan package, specify their package explicitly:

@EnableFeignClients(basePackages = "com.example.clients")

3. Declare Feign Clients Correctly

A Feign client should be an interface annotated with @FeignClient. For example:

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(name = "catalog-service", url = "${catalog.url}")
public interface CatalogClient {

    @GetMapping("/catalog")
    String getCatalog();
}

Provide a service name, and configure a URL when calling a fixed endpoint. If using service discovery, configure the service name and discovery setup appropriate to your application.

4. Check Package Scanning and Configuration

  • Ensure the class containing @EnableFeignClients is part of the Spring application context.
  • Check that Feign interface packages are included in client scanning.
  • Avoid placing Feign configuration in a package that is unintentionally excluded from component scanning.
  • Verify that the application is using Spring Cloud OpenFeign rather than mixing incompatible Feign configurations.

5. Resolve Dependency Version Conflicts

Spring Cloud and Spring Boot versions must be compatible. Inspect the resolved dependency tree for multiple or conflicting Spring Cloud OpenFeign and Feign versions. Use the Spring Cloud BOM recommended for your Spring Boot version instead of manually pinning individual Spring Cloud artifacts.

Conclusion

A missing FeignContext bean is commonly a sign that OpenFeign auto-configuration has not been activated. Confirm that the OpenFeign starter is present, @EnableFeignClients is applied to a scanned configuration class, client interfaces are being discovered, and dependency versions are compatible.

Comments