我的应用程序后台抛出异常。该错误未记录,但由名为 Dynatrace 的第三方工具捕获,由于该工具,我们能够看到下面的异常。
我们正在使用 Java 11 和依赖项:
我从下面的堆栈跟踪中可以了解到,@Cacheable 方法和 @Cacheable 方法内部使用的 @FeignClient 存在一些问题。仅当存在缓存未命中时才会发生此错误。
我尝试用 redisson 替换 jedis,但没有什么区别。有谁知道为什么会这样?
假冒客户:
@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);
}
这是堆栈跟踪:
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)
尝试替换依赖项并从 application.yml 中的 feign 配置中删除定价客户端
我通过定义默认的 Client @Bean 并使用 FeignConfig.class 作为客户端中的配置解决了这个错误
public class FeignConfig {
@Bean
public Client feignClient() {
return new Client.Default(null, null);
}
}
如果您只使用
@SpringBootTest
注释而没有相应的 @SpringBootApplication
带注释的类,则必须在 @EnableFeignClients
旁边同时使用 @ImportAutoConfiguration(FeignAutoConfiguration.class)
和 @SpringBootTest
(或在与 @Configuration
一起使用的 @SpringBootTest
类上) ).