报错信息如下,意思是发现了两个注册中心
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]
首先我们看一下工程目录:
eureka-server是我的eureka服务端,order-server和user-server是我的eureka客户端,在eureka服务端中引入了服务端依赖:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
在两个eureka客户端中引入了客户端依赖:
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency>
当我想将注册中心从eureka切换为nacos时,不仅需要注释掉eureka客户端的依赖,还需要注释掉eureka服务端的依赖。