Field autoServiceRegistration in org.springframework.cloud.client.serviceregistry.AutoServiceRegistr

在学习springcloud时,因为之前教程运行过eureka注册中心,当学到使用nacos作为注册中心时,出现了问题,我启动了两个服务提供者,第一个能正常运行,但是第二个则报了错误,并且代码都是没错的,报错信息如下:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field autoServiceRegistration in org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration required a single bean, but 2 were found:
	- nacosAutoServiceRegistration: defined by method 'nacosAutoServiceRegistration' in class path resource [com/alibaba/cloud/nacos/registry/NacosServiceRegistryAutoConfiguration.class]
	- eurekaAutoServiceRegistration: defined by method 'eurekaAutoServiceRegistration' in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

经过我查了一些大佬写的博客,发现原因是 AutoServiceRegistrationAutoConfiguration 这个类需要自动注入一个类型为AutoServiceRegistration 的 bean。但是在 Spring 容器中,发现了两个父类为 AutoServiceRegistration 的 bean,分别是nacosAutoServiceRegistration 和 eurekaAutoServiceRegistration。这样就导致了自动注入时不知道应该选择使用哪个 bean,进而导致了应用启动失败。

于是你可以给一个bean加上注解@Primary,但我这好像没有啊,找不到,搜索找到的Bean是只读文档,我改不了,后来我发现,只有其中一个模块会出现这样的错误,我就去这个模块中找问题,最终发现是这个模块eureka坐标没注释,看来是nacos和eureka的两个坐标同时存在,所以Spring会不知道注入谁,然后我注释eureka的坐标之后再运行,发现仍旧报错,索性执行clean清除一下坐标,再启动,成功运行!

歪打正着,也算是幸运了= =

 

 

 

  • 8
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值