Eureka切换Nacos时发现两个注册中心的解决方法

问题

spring cloud微服务的注册中心由eureka切换成nacos时,由于maven依赖的问题,有时会出现以下错误:

Field registration in org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration$ServiceRegistryEndpointConfiguration required a single bean, but 2 were found:
    - nacosRegistration: defined by method 'nacosRegistration' in class path resource [org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.class]
    - eurekaRegistration: defined in BeanDefinition defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]

报错信息大概就是服务注册时,发现了两个注册中心,产生冲突了。。。

解决方法

1 引用

需要检查pom文件中的引用,把eureka相关引用删除,重新编译。

2.忽略某一个注册中心

在项目的配置文件中加入以下配置:

spring.autoconfigure.exclude: org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration

如果配置文件是yml格式的,配置内容如下:

spring:
  autoconfigure:
    exclude: org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration

以上配置就是忽略了eureka注册中心

3 直接删除项目中的eureka相关依赖

第一步,找到External Libraries里面eureka的jar包(可用双Shift搜索‘eureka’)
然后在 “spring-cloud-netflix-eureka-client:***” 上右键“Open Library Settings”

在这里插入图片描述
然后右键“Delete”, 删除这个依赖即可
在这里插入图片描述
如此这般,项目可以启动了,但是打包的时候,需要eureka的包还是会被打进去,需要将打好的包中的eureka依赖删除掉。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值