
Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:
Once the early-adopter seats are all used, the price will go up and stay at $33/year.
Last updated: March 17, 2025
It’s common practice to monitor Java applications for performance and stability. Spring Boot provides this monitoring capability via Actuators. However, we may need more fine-grained control or a lightweight way to achieve the same.
Jolokia helps us monitor the application via API endpoints and provides features like bulk operations and security mechanisms at the same time.
In this tutorial, we’ll look at integrating Jolokia into a Spring Boot application.
We’ll now look at the steps needed to enable Jolokia in our application.
To begin with, we need to add the Jolokia dependency to use Jolokia which adds the transitive dependencies and service libraries:
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-support-spring</artifactId>
<version>2.2.1</version>
</dependency>
By default, Spring Boot Actuator only exposes limited endpoints. To enable Jolokia, we need to configure it, in the application’s properties file:
management.endpoints.web.exposure.include=jolokia
Now, with the dependencies added and the application configured, Jolokia will be accessible when we start the Spring Boot application.
Jolokia provides several commands for a variety of tasks:
Next, let’s look at some of these commands.
Let’s navigate to the following endpoint:
http://localhost:8080/actuator/jolokia/version
We should get the following response:
As we can see, we get some information about the version, such as whether it’s secured, whether there’s a proxy, etc.
Now, let’s get a list of all the available MBeans by executing the list command:
http://localhost:8080/actuator/jolokia/list
We can see the list of available beans, along with the allowed operations on each of them:
We’ll try to get information about the Heap Memory usage, using the read command:
http://localhost:8080/actuator/jolokia/read/java.lang:type=Memory/HeapMemoryUsage
As we can observe in the response, the different values for the HeapMemoryUsage attribute are visible:
Let’s initiate garbage collection by executing an exec command:
http://localhost:8080/actuator/jolokia/exec/java.lang:type=Memory/gc
We received a 200 status code, meaning the garbage collection command was accepted:
Getting information or initiating action on any of the exposed MBeans is easy. However, we’ll need to ensure that only expected operations can be performed by a limited number of people with access.
As we’ve observed, Jolokia exposes all the JMX resources by default. This can certainly pose a problem since all users are allowed all the operations which may compromise the application. To avoid this situation, we need to secure the endpoints.
On Production servers, we could completely disable Jolokia by setting the following in the application properties:
management.endpoint.jolokia.enabled=false
We could configure the security rules by creating a jolokia-access.xml file and placing it in the classpath.
Let’s create one so that Jolokia access is secured by the IP address of the user:
<restrict>
<remote>
<host>127.0.0.1</host>
</remote>
</restrict>
And when we try to access the Jolokia endpoint, we get an error as expected:
Next, we’ll try to restrict certain commands or operations. For example, we’ll only allow the read and list commands:
<commands>
<command>read</command>
<command>list</command>
</commands>
Now, let’s try to POST the exec command for garbage collection we tried earlier:
As we can see since we only allowed the read and list operations, the exec command is forbidden.
Finally, we can also allow or deny certain MBean operations that override even the entries in the commands section.
<allow>
<mbean>
<name>java.lang:type=Memory</name>
<operation>gc</operation>
</mbean>
</allow>
<deny>
<mbean>
<name>jdk.management.jfr:type=FlightRecorder</name>
<attribute>*</attribute>
<operation>*</operation>
</mbean>
</deny>
We’ve allowed the gc operation on the Memory MBean. Also, in the deny section, we’ve denied all attributes and operations on the FlightRecorder MBean.
In this article, we learned how to integrate Jolokia with Spring Boot. First, we took a look at the initial setup and some basic commands.
Next, we explored how can we secure the access and operations on various MBeans, namely by restrictions on IP addresses, whitelisting commands, and allowing or denying certain MBeans and their attributes/operations.