zhaohz

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Spring boot启动报“APPLICATION FAILED TO START”错误:DiskSpaceHealthIndicatorAutoConfiguration required a single bean, but 2 were found

具体报错日志如下:

2020-04-21 00:10:16.397 ERROR 25829 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  {cyan} : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'diskSpaceHealthIndicator' defined in class path resource [org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'diskSpaceHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties' available: expected single matching bean but found 2: diskSpaceHealthIndicatorProperties,management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties
2020-04-21 00:10:16.495 ERROR 25829 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   {cyan} : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method diskSpaceHealthIndicator in org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorAutoConfiguration required a single bean, but 2 were found:
    - diskSpaceHealthIndicatorProperties: defined by method 'diskSpaceHealthIndicatorProperties' in class path resource [org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorAutoConfiguration.class]
    - management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

2020-04-21 00:10:16.496 ERROR 25829 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   {cyan} : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method diskSpaceHealthIndicator in org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorAutoConfiguration required a single bean, but 2 were found:
    - diskSpaceHealthIndicatorProperties: defined by method 'diskSpaceHealthIndicatorProperties' in class path resource [org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorAutoConfiguration.class]
    - management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

2020-04-21 00:10:16.496 ERROR 25829 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   {cyan} : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method diskSpaceHealthIndicator in org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorAutoConfiguration required a single bean, but 2 were found:
    - diskSpaceHealthIndicatorProperties: defined by method 'diskSpaceHealthIndicatorProperties' in class path resource [org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorAutoConfiguration.class]
    - management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

2020-04-21 00:10:16.497 ERROR 25829 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   {cyan} : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method diskSpaceHealthIndicator in org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorAutoConfiguration required a single bean, but 2 were found:
    - diskSpaceHealthIndicatorProperties: defined by method 'diskSpaceHealthIndicatorProperties' in class path resource [org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorAutoConfiguration.class]
    - management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties: defined in null


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

问题分析:

网上找不到类似的问题,困扰了我两三天,最初发现和打包方式有关系,打成可执行包是没问题,打成lib依赖包分离的方式就有问题。

后来进一步分析,发现是因为我近期升级了spring boot的版本,旧的版本依赖包在lib里没有没有清除干净,删掉全部依赖包后,重新生成就可以了。

^^ 分享一下,说不定谁又遇到类似的问题。

posted on 2020-04-23 20:54  zzhaoh  阅读(1352)  评论(0编辑  收藏  举报