No fallbackFactory instance of type class 问题处理

  • 1. 错误日志
  • 2.问题原因
  • 3.解决方法

1. 错误日志

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.sx.qm.service.impl.UnitTest': Unsatisfied dependency expressed through field 'remoteEventLogService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sx.mm.api.RemoteEventLogService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.sx.mm.api.factory.RemoteEventLogFallbackFactory found for feign client remoteEventLogServiceat org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:392)at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119)at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:43)at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.ParentRunner.run(ParentRunner.java:413)at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)at org.junit.runners.Suite.runChild(Suite.java:128)at org.junit.runners.Suite.runChild(Suite.java:27)at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)at org.junit.runners.ParentRunner.run(ParentRunner.java:413)at org.junit.runner.JUnitCore.run(JUnitCore.java:137)at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sx.mm.api.RemoteEventLogService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.sx.mm.api.factory.RemoteEventLogFallbackFactory found for feign client remoteEventLogServiceat org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176)at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101)at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1828)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1265)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1532)at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1489)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1270)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)... 38 more
Caused by: java.lang.IllegalStateException: No fallbackFactory instance of type class com.sx.mm.api.factory.RemoteEventLogFallbackFactory found for feign client remoteEventLogServiceat com.alibaba.cloud.sentinel.feign.SentinelFeign$Builder$1.getFromContext(SentinelFeign.java:120)at com.alibaba.cloud.sentinel.feign.SentinelFeign$Builder$1.create(SentinelFeign.java:106)at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:64)at feign.Feign$Builder.target(Feign.java:269)at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:38)at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:318)at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:347)at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:327)at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169)... 49 more

2.问题原因

先来看代码,以下是测试类,它继承了测试公共类

public class UnitTest extends CommonTest {@Autowiredprivate RemoteQmtqService remoteQmtqService;@Autowiredprivate RemoteEventLogService remoteEventLogService;@Testpublic void test4() {List<String> matNoList = new ArrayList<>(2);matNoList.add("PC001");matNoList.add("1");SysEventVO sysEventVO = new SysEventVO();sysEventVO.setEventMaker("n.lu");sysEventVO.setEventTime(new Date());sysEventVO.setEventTypeCode(EventConstant.eventTypeCodeEnum.MM.getCode());sysEventVO.setMatNoList(matNoList);sysEventVO.setSysEvent(EventConstant.SysEventEnum.MM01);sysEventVO.setSystemId(EventConstant.systemCodeEnum.LIMS.getCode());try {remoteEventLogService.log(sysEventVO);} catch (Exception e) {e.printStackTrace();}}
}

再来看测试公共类,它是基于SXQmApplication.class类启动的,所以它扫描的时候也是基于这个类的路径来注入的,SXQmApplication类的包路径为:package com.sx.qm;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SXQmApplication.class})
@WebAppConfiguration
public class CommonTest {@Beforepublic void init() {System.out.println("开始测试-----------------");}@Afterpublic void after() {System.out.println("测试结束-----------------");}
}

但是来看兜底类的路径如下,它的路径为package com.sx.mm.api.factory; 这样它就不会被注入到spring IOC 中,所以导致找不到。

package com.sx.mm.api.factory;import com.sx.mm.api.RemoteEventLogService;
import com.sx.mm.api.domain.EventConstant;
import com.sx.mm.api.domain.SysEventVO;
import feign.hystrix.FallbackFactory;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;import java.util.Date;
import java.util.List;
import java.util.Map;@Component
public class RemoteEventLogFallbackFactory implements FallbackFactory<RemoteEventLogService> {private static final Logger log = LoggerFactory.getLogger(RemoteEventLogFallbackFactory.class);@Overridepublic RemoteEventLogService create(Throwable throwable) {log.error("物料模块-事件服务调用失败:{}", throwable.getMessage());return new RemoteEventLogService(){@Overridepublic String log(SysEventVO sysEventVO) throws Exception{return null;};};}
}

3.解决方法

在启动类加上这句:@ComponentScans(value = {@ComponentScan(“com.sx.mm”)}),启动时去扫描com.sx.mm路径下的组件,这样就能找到了。

@EnableCustomConfig
@EnableCustomSwagger2
@EnableRyFeignClients
@SpringCloudApplication
@MapperScan("com.sx.qm.mapper")
@ComponentScans(value = {@ComponentScan("com.sx.mm")})
public class SXQmApplication
{public static void main(String[] args){SpringApplication.run(SXQmApplication.class, args);System.out.println("质量模块启动成功——————");}
}

No fallbackFactory instance of type class 问题处理相关推荐

  1. No fallbackFactory instance of type class com.chongyou.system.api.factory.RemoteUserFallbackFactory

    记录一下自己的开发报错之路 问题描述 在使用微服务之间的服务调用,并且实现了降级处理的.编译时报错 No fallbackFactory instance of type class com.chon ...

  2. No fallbackFactory instance of type class com.neuray.oa.security.service.system.api.factory.RemoteDe

    feign服务调用,项目启动报错: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating b ...

  3. No fallbackFactory instance of type class com.ruoyi.system.api.factory.RemoteLogFallbackFactory foun

    报错找不到这个类(托底类) /*** 日志服务降级处理* * @author ruoyi*/ @Component public class RemoteLogFallbackFactory impl ...

  4. No enclosing instance of type JDStudent is acAcessible. Must qualify the allocation with an enclosin

    No enclosing instance of type JDStudent is acAcessible. Must qualify the allocation with an enclosin ...

  5. 解决No enclosing instance of type * is accessible

    写一个内部类,并在构造函数中初始化时,遇到报错,搜索问题后发现,有网友出现过类似的问题,下面这个是说的浅显明白的,并确实解决了问题.于是,以下内容照搬过来,不再多费键盘了. public class ...

  6. No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing

    No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing ...

  7. 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 开启熔断,配置 fal ...

  8. Java出现No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosin

    最近研究LDA源代码时,里面涉及到Comparable方法的使用.以前用过这个排序方法,现在想回顾一下.以下是程序,感觉没问题啊,结果报错了: Exception in thread "ma ...

  9. Java变异出现错误:No enclosing instance of type XXX is accessible

    摘要:写java代码时遇到下面的编译错误. 本文分享自华为云社区<Java中出现No enclosing instance of type XXX is accessible问题>,作者: ...

  10. No enclosing instance of type FormDetailBean is accessible. Must qualify the allocation with an encl

    最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现:No enclosing instance of type E is accessible ...

最新文章

  1. C++数据结构链表的基本操作
  2. Hadoop通过路径和和链接访问HDFS
  3. rabitMQ和kafka如何选择
  4. Windows程序设计:MFC 、Winform 和 WPF 比较
  5. MapReduce编程实战之“工作原理”
  6. CT基本概念(必须掌握)
  7. 大爷与支付宝同名,曾想状告阿里巴巴侵权,现在过得怎么样
  8. 飞鸽传书有关举证不够严谨
  9. 引导页设计灵感,高大上的设计案例
  10. 苹果怒封Google、FB:私下购买用户隐私被制裁,数万员工受牵连
  11. 我的python之路(二):python环境安装
  12. 数据库系统原理课程设计
  13. iTOP4412 uboot移植教程
  14. 数据结构:图的深度优先遍历和广度优先遍历
  15. ai修复照片软件是哪个软件_AI照片修复免费版-AI照片修复软件下载v1.1.0安卓版-西西软件下载...
  16. LVGL官方文档-7.11.0-8-Porting-Logging
  17. 618年中大促八大情景话术大全(赶紧收藏)
  18. java计算机毕业设计教师继续教育MyBatis+系统+LW文档+源码+调试部署
  19. 前端ppt\word等等文件实现在线预览功能
  20. 云服务器如何安装docker?

热门文章

  1. win10去除快捷小箭头_【批处理】win 去除桌面图标小箭头
  2. 命令提示符打不开python_Windows-Python在命令提示符下不起作用?
  3. 触动精灵 - 获取颜色相似度
  4. MATLAB超限邻域滤波
  5. FeignClient中每一个@RequestParam 都要设置value,否者报错
  6. 【C#】如何使程序以管理员身份运行
  7. java 中文星期表示_java之获得中文星期几
  8. 函数的length属性
  9. 360度领导能力全方位测试
  10. android 锁屏代码分析,锁屏分析(Android9.0)