Summary:

 

In this article, we will find out how to configure Jolokia on a Spring Boot 2 server. We will also configure Jolokia on a different management port and a different base URL.

 

Background:

 

Jolokia is a JMX over HTTP bridge that allows system administrators to access their MBeans and JMX functionalities over HTTP and JSON. Getting started with Jolokia in a Spring boot environment is a 5 minute job (if you know what you are looking for 😉 ). So let us get started!

 

 

How to configure Jolokia in a Spring boot environment:

 

1 – Add the required dependencies:

The first step is to make sure that your project has the required dependencies. For this, we will add three dependencies to our POM file. First is the Spring boot actuators dependency. This will cause the actuators autoconfiguration to kick-in and enable management endpoints on the server. The second dependency is the Jolokia core. This adds the required Jolokia libraries. The Spring boot actuator autoconfiguration can then pick up the Jolokia libraries to be added as an additional management endpoint to the server.  The third dependency is the starter web dependency. This pulls in all the web autoconfigurations needed to expose the actuators as web management http endpoints.

 

2 – Expose the Jolokia endpoint:

The second step is to tell the Spring boot autoconfiguration to expose Jolokia as an actuator endpoint. This can be done simply by adding Jolokia to the list of exposed endpoints in the application.properties file.

 

If your goal is to expose Jolokia only, then remove the * from the exposure.include property. On a vanilla Spring boot server, the Jolokia interface can be accessed on port 8080. For example, http://localhost:8080/actuator/jolokia . If you get a response like the one in the screenshot below, then Jolokia has been started correctly.

 

 

 

3 – Configuring the Jolokia management port:

By default, the Spring boot actuators will be configured on port 8080. However, this may not be the ideal port for many production configurations. In this case, the actuator port can be customized in the properties file as follows:

Now, the Jolokia (and any other actuator) endpoint will be accessible on port 8912. The new path to the Jolokia actuator endpoint will be http://localhost:8912/actuator/jolokia .

 

4 – Configuring the Jolokia management path:

By default, Jolokia and every other endpoint are available under the /actuator path. This can be changed (for all endpoints) by setting the web base-path property. If you do not like the name “Jolokia”, then this can also be changed by modifying the mapping property. Let us take the following properties as an example:

With this configuration, the Jolokia interface will be accessible with the link http://server:port/endpoints/customjmx

 

Note that all other endpoints will have their base path changed. For example, the health actuator will also be accessible as follows: http://server:port/endpoints/health

 

If you like this content, then please support us by clicking that twitter follow button at the bottom of the page in order to be notified of our latest updates 😉