日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

No fallback instance of type class found for feign client user-service(转)

發(fā)布時(shí)間:2023/12/10 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 No fallback instance of type class found for feign client user-service(转) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

No fallback instance of type class found for feign client user-service(轉(zhuǎn))

1、錯(cuò)誤日志

在 feign 開啟熔斷,配置 fallback 類,實(shí)現(xiàn)當(dāng)前接口的實(shí)現(xiàn)類時(shí),報(bào)錯(cuò)信息如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. ERROR 7204 --- [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException:
  Error creating bean with name
'consumerController':
Unsatisfied dependency expressed through field 'mUserClient';
nested exception is org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'club.sscai.consumer.client.UserClient':
FactoryBean threw exception on object creation;
nested exception is java.lang.IllegalStateException:
  No fallback instance of type class club.sscai.consumer.client.UserClientImpl found for feign client user-service

?

2、通常配置

1、開啟 hystrix(默認(rèn)是關(guān)閉的):feign.hystrix.enabled=true2、Fallback 接口實(shí)現(xiàn)類需要注解 @Component

如果到此處還沒有解決的話?請往下看。

?

3、轉(zhuǎn)載解決方案

跟蹤代碼發(fā)現(xiàn) 是因?yàn)閷eignClient 這個(gè)接口做了AOP切面。

@Pointcut("execution(* com.xx.xx.service.IR*.*(..))") public void remoteCall() { }

Trace日志看到這么一行:

[DEBUG] [17:50:22.410][JdkDynamicAopProxy][117]:
Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.xx.xx.service.HystrixClientFallback@32354b00]

然后考慮是不是因?yàn)镾pring AOP動(dòng)態(tài)代理默認(rèn)為 JDK動(dòng)態(tài)代理。

切面還是要切的,Fallback也不能放棄。因?yàn)檎{(diào)用的是接口,無論如何都要被切。

換成cglib后,問題成功解決。


?

原理
SpringAOP 的動(dòng)態(tài)代理有兩種實(shí)現(xiàn),JDK動(dòng)態(tài)代理,和Cglib。
Spring默認(rèn)使用 JDK動(dòng)態(tài)代理。
當(dāng)類至少實(shí)現(xiàn)了一個(gè)接口時(shí),使用JDK動(dòng)態(tài)代理。上文的Feign的Fallback類正好是這樣。
至于究竟為什么cglib可以成功,就不去深究了,方案就兩個(gè),非此即彼。
至于為什么 找不到 fallback instance?

private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) {List<String> result = new ArrayList<String>();// Check all bean definitions.for (String beanName : this.beanDefinitionNames) {// Only consider bean as eligible if the bean name// is not defined as alias for some other bean.if (!isAlias(beanName)) {try {RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);// Only check bean definition if it is complete.if (!mbd.isAbstract() && (allowEagerInit ||((mbd.hasBeanClass() || !mbd.isLazyInit() || isAllowEagerClassLoading())) &&!requiresEagerInitForType(mbd.getFactoryBeanName()))) {// In case of FactoryBean, match object created by FactoryBean.boolean isFactoryBean = isFactoryBean(beanName, mbd);boolean matchFound = (allowEagerInit || !isFactoryBean || containsSingleton(beanName)) &&(includeNonSingletons || isSingleton(beanName)) && isTypeMatch(beanName, type);......

問題出現(xiàn)在isTypeMatch

這里isTypeMatch 返回了false,因?yàn)轵_不過JVM類型檢查。當(dāng)使用cglib則是匹配的。

?

原文地址:https://www.jianshu.com/p/c8210d878e96

?

posted @ 2018-12-02 00:27 niceyoo 閱讀(...) 評(píng)論(...) 編輯 收藏

總結(jié)

以上是生活随笔為你收集整理的No fallback instance of type class found for feign client user-service(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。