florind
florind

Reputation: 391

Brixton.M4 + zuul: Expected single matching bean but found 2: dropwizardMetricServices,servoMetricServices

I am trying to upgrade a Spring Boot + Spring Cloud based project to Brixton.M4 due to zuul's lack of support for PATCH (https://github.com/spring-cloud/spring-cloud-netflix/issues/412) in the version packaged with SC's Brixton.M3. I have the spring-boot-starter-actuator and spring-cloud-starter-zuul enabled amongst others but now the container fails to start with the following error:

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

More 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

There are indeed two CounterService typed beans in the classpath: DropwizardMetricServices packed in the spring-boot-actuator-1.3.1.RELEASE.jar and ServoMetricServices located in spring-cloud-netflix-core-1.1.0.M4.jar

Is there any way to disable one of those? I checked the documentation but I couldn't find any obvious way.

Thanks!

Upvotes: 1

Views: 641

Answers (2)

Roi Ezra
Roi Ezra

Reputation: 506

Small fix to the above answer

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

Upvotes: 4

rocky
rocky

Reputation: 5004

you can use @Primary for it in your java configuration file like this:

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

Upvotes: 0

Related Questions