PetClinic Monolith Workshop

Building the Spring PetClinic Application

2 min

The first thing we need to set up APM is… well, an application. For this exercise, we will use the Spring PetClinic application. This is a very popular sample Java application built with the Spring framework (via Spring Boot).

First, clone the Spring PetClinic GitHub repository. Later, we will compile, build, package and test the application:

bash
git clone https://github.com/spring-projects/spring-petclinic

Change into the spring-petclinic directory:

bash
cd spring-petclinic
git checkout b26f235250627a235a2974a22f2317dbef27338d

Using Docker, start a MySQL database for PetClinic to use:

bash
docker run -d -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 docker.io/biarms/mysql:5.7

Next, we will start another container running Locust that will generate some traffic in the Spring PetClinic application. Locust is a simple load-testing tool.

bash
docker run --network="host" -d -p 8090:8090 -v ~/workshop/petclinic:/mnt/locust docker.io/locustio/locust -f /mnt/locust/locustfile.py --headless -u 1 -r 1 -H http://127.0.0.1:8083

Next, compile, build and package the application using maven:

bash
./mvnw package -Dmaven.test.skip=true

Note

This command will take a few minutes to complete the first time, because it downloads a lot of dependencies before compiling the application. Future builds will be much quicker.

Once the build completes, you need to obtain the public IP address of the instance you are running on. You can do this by running the following command:

bash
curl http://ifconfig.me

Make a note of the IP address returned by this command, as we will need it to validate that the application is running.