1

zuul で PATCH ( https://github.com/spring-cloud/spring-cloud-netflix/issues/412 )がサポートされていないため、Spring Boot + Spring Cloud ベースのプロジェクトを Brixton.M4 にアップグレードしようとしています。 SC の Brixton.M3 に同梱されているバージョン。私は spring-boot-starter-actuator と 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

より多くのスタックトレース:

 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

クラスパスには実際に 2 つの CounterService タイプの Bean があります。

それらのいずれかを無効にする方法はありますか? ドキュメントを確認しましたが、明白な方法が見つかりませんでした。

ありがとう!

4

2 に答える 2

0

@Primary次のように、Java構成ファイルで使用できます。

@Bean
@Primary
public DropwizardMetricServices dropwizardMetricServices(){
    return new DropwizardMetricServices();
}
于 2016-01-10T07:54:50.013 に答える