How to configure Jolokia on a Spring boot server
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.If you fancy an assistant on your desk to entertain you, tell you about the weather or your appointments, then I recommend the Anki Cozmo – Collector’s Edition robot (click to check the price on Amazon). The Anki Cozmo will entertain you during those boring or lonely moments at work, or while studying, and will help you to keep your schedule and be more alert throughout the day.
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
Adding 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.
Exposing 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.
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 .
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 want to improve your Spring boot skills, then I would suggest that you check out the book “Learning Spring Boot 2.0 – Second Edition: Simplify the development of lightning fast applications based on microservices and reactive programming”(click to check current price on Amazon) by Greg Turnquist. The book covers Spring boot basics and provides an overview of integrating important technologies such as AMQP messaging and REST into your application.
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 😉