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 --- [ 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=true 2、Fallback 接口实现类需要注解 @Component
如果到此处还没有解决的话?请往下看。
3、转载解决方案
跟踪代码发现 是因为对FeignClient 这个接口做了AOP切面。
@Pointcut("execution(* com.xx.xx.service.IR*.*(..))")
public void remoteCall() {
}
Trace日志看到这么一行:
[DEBUG] [::22.410][JdkDynamicAopProxy][]:
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
No fallback instance of type class found for feign client user-service(转)的更多相关文章
- Feign 报错:No fallback instance of type class xxx found for feign client xxx
通常需要确认配置内容: 开启 Hystrix:feign.hystrix.enabled=true Fallback类需要注解@Component 出处:https://www.jianshu.com ...
- 【转】Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing ...
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing--转
原文:http://blog.csdn.net/sunny2038/article/details/6926079 最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一 ...
- No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an
在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...
- No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
之前看内部类的时候没发现这个问题,今天写代码的时候遇到,写个最简单的例子: 下面这一段代码 红色的部分就是编译报错: No enclosing instance of type Outer is ac ...
- No enclosing instance of type Hello is accessible
1.static 关键字 修饰的成员被所有对象共享(包括成员变量和方法). 修饰的成员优先于对象存在. 存储于方法区(共享数据区)的静态区中. 静态方法只能访问静态成员. 静态方法中不可以使用this ...
- Java编译时出现No enclosing instance of type XXX is accessible.
今天在编译Java程序的时候出现以下错误: No enclosing instance of type Main is accessible. Must qualify the allocation ...
- 解决No enclosing instance of type * is accessible
写一个内部类,并在构造函数中初始化时,遇到报错,搜索问题后发现,有网友出现过类似的问题,下面这个是说的浅显明白的,并确实解决了问题.于是,以下内容照搬过来,不再多费键盘了. public class ...
随机推荐
- cocos2dx-lua 文件操作
print("开始") --检查文件是否存在 local path = "ABC.txt" local fileExist = cc.FileUtils:get ...
- 根据SQL_ID查询并杀会话
Oracle 根据SQL_ID查询并杀会话,清空执行计划缓冲池2018年09月06日 10:31:40 小学生汤米 阅读数:4731. 查询最近五分钟内最高频次SQL,查看event select t ...
- Android的路接下来该怎么走?
其实想写这篇文章好久了,很多小伙伴们也经常在群里探讨android移动开发者的走向,一部分人都想多快好省,间歇性踌躇满志.持续性混吃等死 ,只想用CV的开发模式们快速完成工作,然后回家王者农药.其实这 ...
- 网络层HTPPS和HTTP的概念与区别
HTPPS和HTTP的概念 HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP ...
- 传输层的端口与TCP标志中的URG和PSH位
一.协议端口号的提出 运输层提供了进程间通信的能力(即端-端通信).但是不同的操作系统可能无法识别其他机器上的进程.为了用统一的方法对 TCP/IP体系的应用进程进行标志,使运行不同操作系统的计算机的 ...
- Python学习笔记八
类的高级用法 多态: 在其他语言,使用的是类的继承. 在python中,不需要指定数据类型. 基于TCP协议的socket通信实现: 类似于打电话的情景. 服务端: 1.买手机 2.插卡 3.开机 ...
- 多台CentOS服务器下实现SSH免密码登录
ROOT用户下实现SSH免密码登录 第一步:进入目录/root/.ssh $ cd /root/.ssh/ 执行以下命令,会在当前目录下生成公钥(id_rsa.pub)/私钥(id_rsa)对 第二 ...
- spark rdd df dataset
RDD.DataFrame.DataSet的区别和联系 共性: 1)都是spark中得弹性分布式数据集,轻量级 2)都是惰性机制,延迟计算 3)根据内存情况,自动缓存,加快计算速度 4)都有parti ...
- 前后台得到WEB应用的名称
前台得到当前应用的名称: ${ pageContext.request.contextPath } 后台得到当前应用的名称: request.getServletContext().getContex ...
- linux中python3安装和使用
python安装 下载python安装包和依赖环境 #自由选择python3源码包的版本https://www.python.org/ftp/python/https://www.python.org ...