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

我在项目中使用了 eureka作为分布式注册中心,然而在启动一个项目时,却报出了冲突错误。我仔细检查了 我的项目maven文件中并没有添加consul依赖包,父项目中也没有添加该依赖包。之后我又仔细检查了External Librabries 中依赖的jar,发现确实有consul 依赖包。但是我整个父项目中并没有添加该依赖包啊。

consul,eureka冲突

接下来我又去仔细检查了maven中各个子项目的依赖包,发现我启动的那个模块的父模块中确实有该依赖包,但是其父模块的maven文件中并没存在consul依赖。然后。绞尽脑汁之后,突然发现,父模块的 <parent>不对劲,其parent并不是当前项目的模块,而是引用了当初学习分布式开发时候的一个项目,那个项目当时是使用consul作为注册中心的。修改了parent 终于解决了问题!
 

相关文章: