IBM Liberty and SpringBoot - how to implement mpHealth 4.0 `@Readiness` bean

37 Views Asked by At

I'm using Spring Boot 3 in Liberty (without the spring feature in the <featureManager> server.xml file.

I also have mpHealth4.0 in the feature manager section of the xml file.

The default health check works, but the FM does not seem to be aware of beans in the Spring context, so this bean does not get called for a check:

@Readiness
@Component
class ConnectionReadyHealthCheck(val apiClient: APIClient) : HealthCheck {
    companion object {
        val NAME = "apiConnection"
    }
    override fun call(): HealthCheckResponse {
        if(apiClient.isConnected()){
            return HealthCheckResponse.up(NAME)
        } else {
            return HealthCheckResponse.down(NAME)
        }
    }
}

How do I tell MPHealth about this bean in the Spring Context?

1

There are 1 best solutions below

1
Emily Jiang On

MicroProfile provides an alternative programming model to Spring. Unfortunately, you need to choose either MicroProfile or Spring, but you should not mix them.

Open Liberty exposes MicroProfile APIs. The benefit is that you don't need to package the API dependencies inside your application, which is a big difference from the way you write your Spring applications. Open Liberty also provides 1st support for MicroProfile specifications and supports the latest version of MicroProfile releases.

You can find out how to use MicroProfile Health from this Open Liberty guide.