Spring actuator's liveness and readiness are returning 404
Asked Answered
L

3

7

So this is my configuration in application.yaml:

management:
  endpoint:
    health:
      show-details: "ALWAYS"
      probes:
        enabled: true
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: metrics, health, caches, restart

And according to documentations this should be enough for enabling liveness and readiness probe for a spring application. But the endpoints (/actuator/health/liveness and /actuator/health/readiness) are still returning 404. I tried many combinations in the config, but nothing works. Can you please tell me what to do about this?

Liquefacient answered 28/1, 2022 at 21:27 Comment(1)
Hey, did you mange to solve it? need any help?Descombes
L
11

I dug a bit deeper in this issue as I found it as an interesting feature of spring-boot-actuator. From my research I found out that this feature with liveness and readiness has been introduced in spring-boot:2.3.0 so if you're using an older version this might be the reason you're not receiving the expected result when you do a GET /actuator/health/readiness.

If you upgrade your spring-boot version to >= 2.3.0 you can enable the liveness and readiness probes by adding:

management:
  health:
    probes:
      enabled: true

to your application.yaml file. After doing so you should be able to

GET /actuator/health

{
    "status": "UP",
    "groups": [
        "liveness",
        "readiness"
    ]
}

However for spring-boot versions >= 2.3.2 it is advised to enable probes by using the following in your application.yaml

management:
  endpoint:
    health:
      probes:
        enabled: true 

The reason for doing so is a bug which you can read more about here

Extra tip: If you're spring-boot version >= 2.3.0, you've configured your application.yaml file accordingly and you still receive 404 when you GET /actuator/health/liveness there's a slim chance that your application.yaml file is not getting picked up by the Spring Context. You can check if this is the case by changing the port of the application

server:
  port: 8081

If your application doesn't start on a different port, it is safe to say that none of your configurations have taken place. I had this issue one or two times with my IDE.

Lurie answered 2/2, 2022 at 21:45 Comment(1)
you can set this in your application.yaml. Access /health/liveness or /health/readiness management: server.port: 8081 endpoints.web: exposure.include: health base-path: / endpoint: health: probes: enabled: trueActon
D
7

If you work with spring 2.3.2 or newer, please add these properties:

management.endpoint.health.probes.enabled=true
management.health.livenessState.enabled=true
management.health.readinessState.enabled=true
Descombes answered 29/1, 2022 at 7:30 Comment(5)
any description?Carrington
This management.endpoint.health.probes.enabled=true alone enables the liveness and readiness endpoints. You don't need the individual liveness and readiness configsTheosophy
That's right.But depends on the version that you use.Acton
management.endpoint.health.probes.enabled alone works at least since Spring Boot 3.0.2Cambrai
Commit that deprecates management.health.probes.enabled propertyCambrai
F
0

I was getting 404 returned because of the actuator dependency missing in build.gradle file. Add the below line under dependencies in gradle build if everything else looks good as mentioned in fixes above.

implementation 'org.springframework.boot:spring-boot-starter-actuator'

Fez answered 25/7, 2024 at 18:35 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.