title: Spring Boot Actuator: How to get metrics uptime inside a custom HealthIndicator?
body: <p>I want to do a custom HealthIndicator that depends on the application uptime. </p>
  
  <pre><code>@Component
  public class HealthActuator implements HealthIndicator {
  
      private final MetricsEndpoint metricsEndpoint;
  
      @Autowired
      public HealthActuator(MetricsEndpoint metricsEndpoint) {
          this.metricsEndpoint = metricsEndpoint;
      }
  
      @Override
      public Health health() {
          long uptime = (Long) metricsEndpoint.invoke().get("uptime");
          // logic with uptime
          return Health.up().build();
      }
  
  }
  </code></pre>
  
  <p>But there is an error: <code>a circular dependency between 2 beans in the application context</code>.</p>
  
  <p>I can get uptime metric with a rest call to my endpoint /actuator/health.</p>
  
  <p>But maybe is it possible to do it programmatically?</p>
  
  <p>P.S. Log stacktrace:</p>
  
  <pre><code>11-01 14:34:09 WARN org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthActuator' defined in file [/Users/serge/projects/bb/bb-imapl/target/classes/bb/imapl/config/HealthActuator.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$$EnhancerBySpringCGLIB$$2bb06d4a]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'healthActuator': Requested bean is currently in creation: Is there an unresolvable circular reference?
  11-01 14:34:09 WARN org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthActuator' defined in file [/Users/serge/projects/bb/bb-imapl/target/classes/bb/imapl/config/HealthActuator.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration$$EnhancerBySpringCGLIB$$2bb06d4a]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'healthActuator': Requested bean is currently in creation: Is there an unresolvable circular reference?
  11-01 14:34:09 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  There is a circular dependency between 2 beans in the application context:
      - healthActuator defined in file [/Users/serge/projects/bb/bb-imapl/target/classes/bb/imapl/config/HealthActuator.class]
      - org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
      - healthActuator
  
  
  11-01 14:34:09 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 
  </code></pre>