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

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

1、错误日志

在 feign 开启熔断,配置 fallback 类,实现当前接口的实现类时,报错信息如下:

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(默认是关闭的):feign.hystrix.enabled=true2、Fallback 接口实现类需要注解 @Component

如果到此处还没有解决的话?请往下看。

 

3、转载解决方案

跟踪代码发现 是因为对FeignClient 这个接口做了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]

然后考虑是不是因为Spring AOP动态代理默认为 JDK动态代理。

切面还是要切的,Fallback也不能放弃。因为调用的是接口,无论如何都要被切。

换成cglib后,问题成功解决。


 

原理
SpringAOP 的动态代理有两种实现,JDK动态代理,和Cglib。
Spring默认使用 JDK动态代理。
当类至少实现了一个接口时,使用JDK动态代理。上文的Feign的Fallback类正好是这样。
至于究竟为什么cglib可以成功,就不去深究了,方案就两个,非此即彼。
至于为什么 找不到 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);......

问题出现在isTypeMatch

这里isTypeMatch 返回了false,因为骗不过JVM类型检查。当使用cglib则是匹配的。

 

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

 

posted @ 2018-12-02 00:27 niceyoo 阅读(...) 评论(...) 编辑 收藏

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414636.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Redis在windows下安装过程

https://www.cnblogs.com/M-LittleBird/p/5902850.html 一、下载windows版本的Redis 去官网找了很久&#xff0c;发现原来在官网上可以下载的windows版本的&#xff0c;现在官网以及没有下载地址&#xff0c;只能在github上下载&#xff0c;官网只提供linux版本的下载 官网下载…

前端学习(2735):重读vue电商网站45之项目优化上线

优化Vue项目&#xff0c;部署Vue项目 项目优化 添加进度条 nprogress 进度条官方文档传送门 打开 vue-ui 面板&#xff0c;选择依赖&#xff0c;输入 nprogress 进行安装相关依赖。 npm Javascript npm install --save nprogress在 main.js 入口文件中&#xff0c;进行相关…

Push rejected: Push to origin/master was rejected

Push rejected: Push to origin/master was rejected 1、错误日志 23:04 Maven projects need to be imported: Import Changes Enable Auto-Import23:05 4 files committed: 初始化项目23:06 Push rejected: Push to origin/master was rejected23:07 2 files …

基本卷-动态卷性能测评(未完待续)

320G 同一磁盘复制1G 1个文件 //基本磁盘 27秒 FastCopy 1.62 128M缓存 37秒 Windows自带复制 //动态卷 15秒 Windows自带复制 27秒 FastCopy 1.62 128M缓存 28秒 FastCopy 1.62 32M缓存 320G 同一磁盘复制1G 4470个文件 //动态卷 54秒 Windows自带复制 考虑是否是磁盘的原因 3…

前端学习(2736):重读vue电商网站46之执行build 时报错

Error: No module factory available for dependency type: CssDependency 解决办法&#xff1a; 参考&#xff1a;解决webpack打包报错 No module factory available for dependency type: CssDependency 在执行 build 命令期间移除所有的 console babel-plugin-transform…

Android 获取光线强弱,开启闪光灯,关闭闪光灯

1、获取光线强度 &#xff08;1&#xff09;实现传感器接口 implements SensorEventListener 实例化 private SensorManager mSensroMgr;//传感器管理类 mSensroMgr (SensorManager) getSystemService(Context.SENSOR_SERVICE); &#xff08;2&#xff09;监听传感器 Ove…

Python 文件 fileno() 方法

描述 Python 文件 fileno() 方法返回一个整型的文件描述符(file descriptor FD 整型)&#xff0c;可用于底层操作系统的 I/O 操作。 语法 fileno() 方法语法如下&#xff1a; fileObject.fileno() 参数 无 返回值 返回文件描述符。 实例 以下实例演示了 fileno() 方法的使用&am…

@RequestParam @PathVariable

RequestParam PathVariable 1、Request参数 在访问各种各样网站时&#xff0c;经常会发现网站的URL的最后一部分形如&#xff1a;&#xff1f;xxxxyyyy&zzzzwwww。这就是HTTP协议中的Request参数&#xff0c;它有什么用呢&#xff1f;先来看一个例子&#xff1a; 在知乎中…

前端学习(2737):重读vue电商网站47之生成打包报告

打包时&#xff0c;为了直观地发现项目中存在的问题&#xff0c;可以在打包时生成报告。生成报告的方式有两种&#xff1a; ① 通过命令行参数的形式生成报告 Javascript // 通过 vue-cli 的命令选项可以生成打包报告 // --report 选项可以生成 report.html 以帮助分析包内容 …

蓄水池抽样算法 Reservoir Sampling

2018-03-05 14:06:40 问题描述&#xff1a;给出一个数据流&#xff0c;这个数据流的长度很大或者未知。并且对该数据流中数据只能访问一次。请写出一个随机选择算法&#xff0c;使得数据流中所有数据被选中的概率相等。 问题求解&#xff1a;如果是长度已知或者有限的问题&…

Android okhttp3使用实例,OKhttp设置请求超时时间,okgo使用demo,SSL证书验证

SSL证书验证 rootca证书资源 调用 //信任所有证书 HTTPSCerUtils.setTrustAllCertificate(okHttpBuilder); //信任raw资源目录下的证书 HTTPSCerUtils.setCertificate(context, okHttpBuilder, R.raw.rootca); //传入证书…

@ResponseBody ResponseEntity

ResponseBody ResponseEntity 1、产生疑问 我们知道&#xff0c;如果在 Controller 的某个方法上加上 ResponseBody 注解&#xff0c;那么你就能拿到 json 数据。 如果你只是知道这么用&#xff0c;那么你应该知道 ResponseBody 的具体作用&#xff1a; 其将方法的返回值通过…

前端学习(2738):重读vue电商网站48之通过 chainWebpack 自定义打包入口

示例代码如下&#xff1a; Javascript module.exports {chainWebpack: config > {config.when(process.env.NODE_ENV production, config > {config.entry(app).clear().add(./src/main-prod.js)})config.when(process.env.NODE_ENV development, config > {confi…

22图的遍历

图的遍历 图的遍历&#xff1a;搜索属于图的基本运算。树的先序遍历和按层遍历的推广。图的遍历也称搜索&#xff0c;主要有&#xff1a; 先深搜索&#xff08;depth-first search&#xff09;——深度优先搜索——dfs搜索 先广搜索&#xff08;breadth-first search&#xff0…

Cannot resolve symbol 'R',Failed to resolve: constraint-layout

1、当在github上下载demo项目在Android studio启动时&#xff0c;提示Cannot resolve symbol R。虽然提示错误&#xff0c;但是运行项目并没有问题 原因是gradle版本高于本地Android studio的gradle版本 把 classpath com.android.tools.build:gradle:3.3.1 改为 classpat…

Vue中import引入模块路径时的@符号

Vue中import引入模块路径时的符号 1、ES6 模块主要有两个功能&#xff1a;export 和 import export&#xff1a;用户对外输出本模块&#xff08;一个文件可以理解为一个模块&#xff0c;比如 aaa.js bbb.js&#xff09;变量的接口 。 import&#xff1a;用于在一个模块中加载另…

Android Log工具类,Toast工具类,获取当前方法名称

Log新晋工具方法 public class LgqLog {private static boolean ifShowtrue;private static int sCurrentLogLevel Log.DEBUG;private static String sPrefix null;IntDef({ Log.VERBOSE, Log.DEBUG, Log.INFO, Log.WARN, Log.ERROR })Retention(RetentionPolicy.SOURCE)publ…

npm run dev/build/serve

npm run dev/build/serve 1、ERR引发的思考 npm run dev npm ERR! missing script: devnpm ERR! A complete log of this run can be found in: npm ERR! E:\nodejs\node_cache\_logs\2018-12-12T15_06_08_674Z-debug.log 创建好的 vue 项目直接执行 vue run dev 报错&…

前端学习(2739):重读vue电商网站49之第三方库使用CDN

通过 externals 加载外部 CDN 资源 默认情况下&#xff0c;通过 import 语法导入的第三方依赖包&#xff0c;最终会被打包合并到同一个文件中&#xff0c;从而导致打包成功后&#xff0c;单文件体积过大的问题。 例如上述 chunk-vendors.js 体积很大&#xff0c;原因是全部 im…

Mysql--重点1

知识预览 sql语句规范数据类型数据库操作数据表操作表记录操作查询表记录(select)多表查询完整性约束回到顶部sql语句规范 sql是Structured Query Language(结构化查询语言)的缩写。SQL是专为数据库而建立的操作命令集&#xff0c;是一种功能齐全的数据库语言。 在使用它时&…