Spring JavaMelody Tutorial

Tutorial describing how to integrate JavaMelody with Spring or Spring Boot 1 application. If we are developing the Spring Boot 2 application, we can use the javamelody-spring-boot-starter as described here. In other case we have to provide own confguration as follows.

Technologies used:

  1. Spring Boot 1.5.22.RELEASE
  2. JDK 1.8
  3. Maven 3
  4. JavaMelody

Project setup

Project dependencies managed by the Maven’s pom.xml configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">



            <groupId>net.bull.javamelody </groupId>


The explanation of above dependencies:

  • spring-boot-starter-web – packages all the necessary dependencies together with the auto configuration for running simple web application
  • javamelody-core – provides dependencies for JavaMelody monitoring tools
  • spring-boot-maven-plugin – plugin prividing commands to work with a Spring Boot application (we will be usine the spring-boot:run command)

JavaMelody Configuration

public class JavaMelodyConfiguration {

public SessionListener monitoringSessionListener() {
return new SessionListener();

public FilterRegistrationBean monitoringFilter() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
MonitoringFilter filter = new MonitoringFilter();

registrationBean.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);

registrationBean.addInitParameter(Parameter.LOG.getCode(), Boolean.toString(true));
return registrationBean;

The minimal configuration for enabling JavaMelody defines two beans:

  • monitoringSessionListener – defines JavaMelody session listener
  • monitoringFilter – defines monitoring filter. Thanks to using FilterRegistrationBean we have better control over the custom initialization of the MonitoringFilter.

Application Initializer

public class SpringBootWebApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);


public class HelloWorldController {

public String hello() {
return "Hello World";


The project can be started by the running the following command:

mvn clean spring-boot:run

By visiting the localhost:8080/hellourl, we should see the page with “Hello World” text.

By visiting the localhost:8080/monitoringurl, we can see JavaMelody reports.

The example code you can download from here

Leave a Reply

Your email address will not be published. Required fields are marked *