当前位置: 首页 > 知识库问答 >
问题:

brixton.m4+zuul:需要一个匹配bean,但找到2个:dropwizardMetricServices、ServerMetricServices

古弘
2023-03-14

由于Zuul不支持与SC的brixton.m3打包的版本中的补丁(https://github.com/spring-cloud/spring-cloud-netflix/issues/412),我正在尝试将一个基于Spring Boot+Spring Cloud的项目升级到brixton.m4。我启用了Spring-boot-starter-actul和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

有什么办法可以让其中的一个失效吗?我查了文件,但找不到任何明显的方法。

谢谢!

共有1个答案

高奇
2023-03-14

您可以在java配置文件中使用@primary:

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(){
    return new DropwizardMetricServices();
}
 类似资料: