步骤
- 启动nacos服务
- 从项目中注释掉spring-cloud-starter-eureka,或者netflix的eureka相关依赖 (如未完全注释,出现下面异常)
- 引入nacos依赖
- 修改配置文件,启动项目
未完全注释eureka依赖
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]
原因在于eureka的maven依赖还在,如果使用idea工具,用maven helper插件打开项目maven依赖图,搜索eureka找到项目在哪里依赖了eureka-client,注释掉即可。