How to add health endpoint in Apache Tomcat 9?

Viewed 16

I am using Apache Tomcat 9 server as a Maven dependency in my project. It is working fine and now I need to add a health endpoint so that it will return 200 OK if everything is running fine.

I came to know about HealthCheckValve (https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Health_Check_Valve) option in Tomcat 9 which is helpful. But I am not been able to figure out where to add this and the process of configuring this valve. As I know if server is standalone we can configure in Server.xml but as the Tomcat Server is a maven dependency I don't know how and where I should configure this.

Can somebody please help me in configuring health endpoint in Apache Tomcat 9 (as a maven dependency) ?

1 Answers

See the documentation, then add the HealthCheckerValve to server.xml. Valves go into either the Engine, Host or Context element. In the server.xml packaged with Tomcat you can find comments that should direct you to the right location.

When embedding a version of Tomcat, you won't have this file available, and so you need to assemble instances of these containers programmatically.

Check the launcher application in this example: https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/basic_app_embedded_tomcat/basic_app-tomcat-embedded.html While I could not find methods like addValve() I found an init() method that you could use to provide a server.xml which will be read by Tomcat.

Related