【已解决】springcloud feign 启动报错Caused by: org.springframework.beans.factory.BeanCreationException: Error

导读:本篇文章讲解 【已解决】springcloud feign 启动报错Caused by: org.springframework.beans.factory.BeanCreationException: Error,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

出错分析

小编在一个微服务项目中,进行feign的远程调用时,由于是跨服务之间的feign接口调用,出现了扫描不到接口的错误,也就是出错的原因!

写在前面:
赶时间的小伙伴直接提高扫描的范围即可,在启动类上添加:
@ComponentScan(basePackages = "com.pig4cloud.pig.*.*")

小编给出我们的服务架构图,小伙伴对比看一下是否一样的问题:
在这里插入图片描述
报错信息:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.pig4cloud.pig.wms.feign.RemoteProductService': Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No fallbackFactory instance of type class com.pig4cloud.pig.wms.feign.factory.RemoteProductServiceFallbackFactory found for feign client remoteProductService
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
	... 34 common frames omitted
Caused by: java.lang.IllegalStateException: No fallbackFactory instance of type class com.pig4cloud.pig.wms.feign.factory.RemoteProductServiceFallbackFactory found for feign client remoteProductService
	at com.pig4cloud.pig.common.feign.ext.PigSentinelFeign$Builder$1.getFromContext(PigSentinelFeign.java:109)
	at com.pig4cloud.pig.common.feign.ext.PigSentinelFeign$Builder$1.create(PigSentinelFeign.java:99)
	at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:64)
	at feign.Feign$Builder.target(Feign.java:269)
	at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:330)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:360)
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:339)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:230)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1231)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1173)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524)
	... 43 common frames omitted

根本原因:
我们可以看到feign的扫描是扫描不到我们另外一个服务的,这时需要我们使用spring的注解@ComponentScan来扩大搜索范围。我们需要扩大扫描的范围:com.pig4cloud.pig.nscom.pig4cloud.pig.wms,我们可以可以合并一下:com.pig4cloud.pig.*.*。第一个*为两个服务下的ns和wms,我们需要扫描下面的所有包我们直接使用第二个*

在这里插入图片描述

解决方案

在启动类上添加:
@ComponentScan(basePackages = "com.pig4cloud.pig.*.*")
重启完美解决,解决的小伙伴一键三连走起来哈!!


有缘人才可以看得到的哦!!!

点击访问!小编自己的网站,里面也是有很多好的文章哦!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/85188.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!