Spring cloud Brixton.M4+;zuul:应为单个匹配bean,但找到2:dropwizardMetricServices,servoMetricServices

Spring cloud Brixton.M4+;zuul:应为单个匹配bean,但找到2:dropwizardMetricServices,servoMetricServices,spring-cloud,netflix,netflix-zuul,Spring Cloud,Netflix,Netflix Zuul,我正在尝试将一个基于Spring Boot+Spring云的项目升级到Brixton.M4,因为zuul在与SC的Brixton.M3打包的版本中缺乏对补丁()的支持。 我启用了spring boot starter执行器和spring cloud starter zuul,但现在容器无法启动,出现以下错误: No qualifying bean of type [org.springframework.boot.actuate.metrics.CounterService] is define

我正在尝试将一个基于Spring Boot+Spring云的项目升级到Brixton.M4,因为zuul在与SC的Brixton.M3打包的版本中缺乏对补丁()的支持。 我启用了spring boot starter执行器和spring cloud starter zuul,但现在容器无法启动,出现以下错误:

No qualifying bean of type [org.springframework.boot.actuate.metrics.CounterService] is defined:
expected single matching bean but found 2: dropwizardMetricServices,servoMetricServices
更多stacktrace:

 Could not autowire field: private org.springframework.boot.actuate.metrics.CounterService org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration.counterService; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: 
No qualifying bean of type [org.springframework.boot.actuate.metrics.CounterService] is defined: expected single matching bean but found 2: dropwizardMetricServices,servoMetricServices
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 34 more 
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.boot.actuate.metrics.CounterService] is defined: expected single matching bean but found 2: dropwizardMetricServices,servoMetricServices
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1126)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 36 more
类路径中确实有两个CounterService类型的bean:spring-boot-exactor-1.3.1.RELEASE.jar中打包的DropwizardMetricServices和spring-cloud-netflix-core-1.1.0.M4.jar中的ServoMetricServices

有没有办法禁用其中一个?我查阅了文件,但找不到任何明显的方法


谢谢

您可以在java配置文件中对其使用
@Primary
,如下所示:

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(){
    return new DropwizardMetricServices();
}

您可以在java配置文件中对其使用
@Primary
,如下所示:

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(){
    return new DropwizardMetricServices();
}

对上述答案的小小修正

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(MetricRegistry metricRegistry){
    return new DropwizardMetricServices(metricRegistry);
}

对上述答案的小小修正

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(MetricRegistry metricRegistry){
    return new DropwizardMetricServices(metricRegistry);
}