搜索
简帛阁>技术文章>spring cloud feign 启动报错 java.lang.IllegalStateException: No fallback instance of type class

spring cloud feign 启动报错 java.lang.IllegalStateException: No fallback instance of type class

今天项目启动,突然发现feign启动报错,失败了,之前都没有发生。
报错信息

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springblade.demo.feign.BlogClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No fallback instance of type class org.springblade.demo.feign.BlogClientFallback found for feign client blade-demo
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:178)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1674)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1248)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:257)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1478)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1435)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1218)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1175)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
	... 19 common frames omitted
Caused by: java.lang.IllegalStateException: No fallback instance of type class org.springblade.demo.feign.BlogClientFallback found for feign client blade-demo
	at org.springframework.cloud.openfeign.BladeHystrixTargeter.getFromContext(BladeHystrixTargeter.java:83)
	at org.springframework.cloud.openfeign.BladeHystrixTargeter.targetWithFallback(BladeHystrixTargeter.java:75)
	at org.springframework.cloud.openfeign.BladeHystrixTargeter.target(BladeHystrixTargeter.java:51)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)
	... 31 common frames omitted

查看代码里面,fallback是存在的。
查了网上的帖子,都是说没有把fallback加上@component。

代码里面也是带着的。

所以不是这个问题。后面想起来,springboot启动时候扫描的包是在启动类平级和以下的,由于feign客户端和fallback在微服务中一般都是抽出来放在api模块,导致扫描不到fallback类。所以在启动类的地方,要手动添加扫描包的位置。

加上包扫描的位置之后,启动就成功了

现在还有一个问题,就是这个报错是突然发生的,也就是说之前是没有问题的,代码也没有变动,不知有没有大佬给我解释一下,为什么之前不加这个也可以成功。

Java小白修炼手册

今天项目启动,突然发现feign启动,失败了,之前都没有发生。信息Causedby:orgspringframeworkbeansfactoryBeanCreationException:E
(一)项目环境和问题描述项目环境:JDK18+apachemaven339+idea20183SpringBoot+SpringCloud+Redis+分布式微服务架构需要实现的功能:需求:实现red
feign结合熔断机制的时候:Nofallbackinstanceoftypeclassfoundforfeignclient首先,原因缺少注解“@Component”,导致编译时未将“Fe
在使用springCloud的熔断机制时,在调用方法时报,熔断的类为RemoteNettyServerServiceFallbackFactoryjava@Componentpublicclass
1、错误日志在feign开启熔断,配置fallback类,实现当前接口的实现类时,信息如下:ErrorstartingApplicationContextTodisplaythecondition
坑5、无法扫描到引入包的服务降级实现,大多数情况我们要对feignClient接口显式声明一个fallback以便进行服务降级但是如果你的feignclient接口不在springboot的启动类的子
[[情况:]]feign中使用Hystrix,:Nofallbackinstanceoftypeclassfoundforfeignclient[源码:]@FeignClient(value
[[情况:]]feign中使用Hystrix,:Nofallbackinstanceoftypeclassfoundforfeignclient[源码:]@FeignClient(value
在springboot项目中使用feign组件时,出现异常如下同时也配置了注解但依然原因:该启动类只能找到该包及其子类的注解,无法识别熔断处理类上的@Component注解,需要在启动类加上@Co
在SpringCloud的项目中,我们使用了自动配置的OAuth2RestTemplate,RestTemplate,但是在使用这些restTemplate的时候,url必须是服务的名称,如果要调用真