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里沒有沒有清除干凈,刪掉全部依賴包后,重新生成就可以了。
^^ 分享一下,說不定誰又遇到類似的問題。