Use the following commands to build run the application:
$ mvn clean package
$ java -jar target/livelessons-operations-actuator-1.0.0-SNAPSHOT.jar
Check the health of the application by hitting the /health endpoint.
This sample demonstrates a custom HealthIndicator
and HealthAgregator
. It also
shows how you can remap status code responses.
By default Spring Boot doesn’t expose all the information used tell if an application
is healthy, you just get a single status response. This application has
endpoints.health.sensitive
set to false
to show all information in the JSON.
You can easily write your own HealthIndicator
to extend the standard ones provided by
Spring Boot. The ExampleHealthIndicator
in this project randomly returns up
or
outOfService
. Refresh your browser several times on the /info
endpoint and you should
see the health toggle.
The HealthAggregator
interface is responsible for combining all health results into a
single response. In this project we have a ExampleHealthAgregator
which re-orders which
status has the highest priority.
By default Spring Boot will map OK
status to HTTP 200
and DOWN
or OUT_OF_SERVICE
to HTTP 503
. You can customize this in the application properties. This sample uses:
endpoints.health.mapping.OUT_OF_SERVICE=i-am-a-teapot
To remap OUT_OF_SERVICE
to HTTP 418
(an IETF April Fools' joke in RFC 2324)