Search code examples
spring-bootspring-cacheopenfeign

No qualifying bean of type 'feign.Client' available being thrown in the background


There is an exception being thrown in the background of my application. The error is not logged but it's caught by a third-party tool called Dynatrace, due to this tool we were able to see the exception below.

We are using Java 11 and the dependencies:

  • spring-boot-starter-parent 2.7.5
  • spring-cloud-dependencies 2021.0.5
  • spring-boot-starter-web
  • spring-boot-starter-aop
  • spring-cloud-starter-sleuth
  • spring-cloud-starter-openfeign
  • spring-boot-starter-data-redis
  • spring-boot-starter-cache
  • jedis
  • spring-boot-starter-actuator
  • spring-boot-starter-web

What I can understand from the stack trace below is that there is some issue with a @Cacheable method and the @FeignClient that is being used inside the @Cacheable method. This error only happens when there is a cache miss.

I've tried replacing the jedis with redisson but it made no difference. Does anyone know why this is happening?

Feign client:

@FeignClient(name = "pricing-client", url = "${api.pricing.url}")
public interface PricingClient {

    @PostMapping(consumes = "application/json")
    ResponseEntity<String> postRule(@RequestHeader("Authorization") String authorizationToken, @RequestBody PricingRequest request);

}

This is the stack trace:

Exception:
org.springframework.beans.factory.NoSuchBeanDefinitionException

Message:
No qualifying bean of type 'feign.Client' available

Stacktrace:
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351)
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342)
org.springframework.cloud.sleuth.instrument.web.client.feign.LazyClient.delegate(LazyClient.java:60)
org.springframework.cloud.sleuth.instrument.web.client.feign.LazyClient.execute(LazyClient.java:54)
feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:121)
feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:91)
feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100)
org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory$1.proceed(FeignCachingInvocationHandlerFactory.java:66)
org.springframework.cache.interceptor.CacheInterceptor.lambda$
org.springframework.cache.interceptor.CacheInterceptor$$Lambda$.invoke
org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:351)
org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:64)
org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory.lambda$
org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory$$Lambda$.invoke
com.sun.proxy.$Proxy.postRule
com.custom.calc.services.CustomPricingService.getCustomRule(CustomPricingService.java:50)
com.custom.calc.services.CustomPricingService$$FastClassBySpringCGLIB$$377e0b96.invoke(<generated>)
org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
org.springframework.cache.interceptor.CacheInterceptor.lambda$
org.springframework.cache.interceptor.CacheInterceptor$$Lambda$.invoke
org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:366)
org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:421)
org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345)
org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:64)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
com.custom.calc.services.CustomPricingService$$EnhancerBySpringCGLIB$$.getCustomRule
com.custom.calc.services.PricingResilientService.getCustomRule(PricingResilientService.java:28)
com.custom.calc.services.CalculateCustomService.calculateBalance(CalculateCustomService.java:32)
com.custom.calc.controllers.CalculateCustomController.calculateBalance(CalculateCustomController.java:35)
jdk.internal.reflect.NativeMethodAccessorImpl.invoke0
jdk.internal.reflect.NativeMethodAccessorImpl.invoke
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke
java.lang.reflect.Method.invoke
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)

Tried replacing dependencies and removing the pricing-client from feign config in application.yml


Solution

  • I solved this error by defining a default Client @Bean and using the FeignConfig.class as the configuration in the client

    public class FeignConfig {
    
        @Bean
        public Client feignClient() {
            return new Client.Default(null, null);
        }
    
    }