2016-01-09 53 views
1

由於zuul缺少對PATCH(https://github.com/spring-cloud/spring-cloud-netflix/issues/412)的支持,我正試圖將基於Spring Boot + Spring Cloud的項目升級到Brixton.M4版本與SC的Brixton.M3一起打包。 我有彈簧引導起動致動器和彈簧雲起動zuul啓用在其他之中,但現在的集裝箱未能啓動並出現以下錯誤:Brixton.M4 + zuul:預期的單個匹配bean,但找到2:dropwizardMetricServices,servoMetricServices

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

更多堆棧跟蹤:

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:DropwizardMetricServices打包在spring-boot-actuator-1.3.1.RELEASE.jar和位於spring-cloud-netflix-core-1.1.0.M4.jar中的ServoMetricServices

有什麼辦法可以禁用 其中一個?我檢查了文檔,但我找不到任何明顯的方法。

謝謝!

回答

0

你可以使用@Primary它在你的java配置文件是這樣的:

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

小修覆上述答案

@Bean 
@Primary 
public DropwizardMetricServices dropwizardMetricServices(MetricRegistry metricRegistry){ 
    return new DropwizardMetricServices(metricRegistry); 
} 
相關問題