Disable and Replace Default DataSourceHealthIndicator
<p>I am currently working with a health monitoring framework implemented using the Spring Boot Actuator "health" endpoint. The Actuator infrastructure supports the creation of custom health checks and also provides a number of built-in health checks; one of these is <code>DataSourceHealthIndicator</code>.</p>

<p><a href="https://github.com/spring-projects/spring-boot/blob/v1.4.0.RELEASE/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/DataSourceHealthIndicator.java" rel="nofollow noreferrer"><code>DataSourceHealthIndicator</code></a> is part of the <a href="https://github.com/spring-projects/spring-boot/tree/master/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health" rel="nofollow noreferrer"><code>org.springframework.boot.actuate.health</code></a> package, and is currently being used by our health framework to check the health of data sources. I have a need to use my own, slightly modified version of <code>DataSourceHealthIndicator</code> and to disable the "default."</p>

<p>I have tried the solutions suggested <a href="https://stackoverflow.com/questions/24873283/issue-with-datasourcehealthindicator-in-spring-boot-actuator">here</a> and <a href="https://stackoverflow.com/questions/29865940/spring-boot-actuator-health-indicator">here</a>, with no luck. What could I be doing wrong?</p>

<p>Thanks!</p>

<hr>

<p><strong>Edit: 8/18/2016, 3:38 PM EST</strong></p>

<p>I've renamed my bean to <code>dbHealthIndicator</code> and added the following to my configuration class:  </p>

<pre><code>@Bean
public HealthIndicator dbHealthIndicator() {
     return new dbHealthIndicator();
}
</code></pre>

<p>I am now getting the following exceptions:  </p>

<p><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataAccessMapperFactory' defined in class path resource [udtContext.xml]</code></p>

<p><code>java.lang.RuntimeException: java.sql.SQLException: Unable to start the Universal Connection Pool: oracle.ucp.UniversalConnectionPoolException</code></p>

<hr>

<p><strong>Edit: 8/19/2016, 9:22 AM EST</strong></p>

<p>This may help to demonstrate what I am trying to do. Currently, my <code>/health</code> endpoint returns something that looks like this:</p>

<pre><code>dataSource: {
     status: "UP",
     database: "mySql",
     hello: "hello"
}
</code></pre>

<p>I would like for it to return something more like this, where the integer beside "result" is a status code returned by a stored procedure in my database:</p>

<pre><code>dataSource: {
     status: "UP",
     database: "mySql",
     hello: "hello",
     result: 0
}
</code></pre>

<p>This is the method in <code>DataSourceHealthIndicator.java</code> that performs the check:</p>

<pre><code>private void doDataSourceHealthCheck(Health.Builder builder) throws Exception {
    String product = getProduct();
    builder.up().withDetail("database", product);
    String validationQuery = getValidationQuery(product);
    if (StringUtils.hasText(validationQuery)) {
        try {
            // Avoid calling getObject as it breaks MySQL on Java 7
            List&lt;Object&gt; results = this.jdbcTemplate.query(validationQuery,
                    new SingleColumnRowMapper());
            Object result = DataAccessUtils.requiredSingleResult(results);
            builder.withDetail("hello", result);
        }
        catch (Exception ex) {
            builder.down(ex);
        }
    }
}
</code></pre>

<p>I need to add eight lines of code to this method, under <code>builder.withDetail("hello", result);</code>, to perform the call to the stored proc. I do not want to "decompile" the default class, and I am unable to override this method because it is private. I was thinking I could copy the <code>DataSourceHealthIndicator.java</code> code in my own bean, add my code, and rewire Spring to use this version instead, but I don't know if this is possible.</p>