简体   繁体   中英

No qualifying bean of type 'org.springframework.boot.actuate.metrics.MetricsEndpoint'

I upgraded spring.version from 5.0.18.RELEASE to 5.3.21

and spring.boot.version from 2.1.18.RELEASE to 2.7.0

spring-boot-starter-actuator ${spring.boot.version}

In my Healthcheck class I use:

@Autowired private MetricsEndpoint metrics;

After upgrade I've got:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthcheck':
Unsatisfied dependency expressed through field 'metrics'; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'org.springframework.boot.actuate.metrics.MetricsEndpoint' available: 
expected at least 1 bean which qualifies as autowire candidate. 
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Why Spring doesn't see org.springframework.boot.actuate.metrics.MetricsEndpoint ?

2.1.18.RELEASE to 2.7.0 is an enormous jump, so as the comment says I'd suggest checking the upgrade guide carefully.

Nonetheless, you need to expose the metrics endpoint in your config, which will create the bean.

management.endpoints.web.exposure.include: metrics

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM