DEV Community

Cover image for Micronaut PetClinic
Mitz
Mitz

Posted on

Micronaut PetClinic

I tried implementing Spring PetClinic with Micronaut instead of using Spring.

https://github.com/bufferings/micronaut-petclinic

The application uses Thymeleaf, JPA(Hibernate) and DI. But it starts in a few hundreds of millis with GraalVM native image. It's so fast!

In this picture, it started in 324ms:

Screen Capture

I haven't yet implemented all the features and it's still very dirty, but basic features work.

How to try (not native image)

1. Clone the Project

git clone https://github.com/bufferings/micronaut-petclinic.git
cd micronaut-petclinic
Enter fullscreen mode Exit fullscreen mode

2. Start PostgreSQL

This Petclinic uses PostgreSQL. You could start PostgreSQL with docker:

docker-compose up
Enter fullscreen mode Exit fullscreen mode

3. Run Application

./mvnw compile exec:exec
Enter fullscreen mode Exit fullscreen mode

3-2. Or you can run it from JAR

./mvnw package
java -jar target/micronaut-*.jar
Enter fullscreen mode Exit fullscreen mode

4. Access PetClinic

You can then access petclinic here: http://localhost:8080/

With JAR file, it takes around 5s to start the app on my laptop.

How to try native image

Micronaut supports GraalVM native image. So I made this PetClinic run as native image.

./mvnw package && docker build -t micronaut-petclinic .
Enter fullscreen mode Exit fullscreen mode

I usually have ☕ (around 10 mins on my laptop) to wait for the build finishes.

# Docker for Mac or Windows
export HOST_NAME=host.docker.internal
# Linux
export HOST_NAME=172.17.0.1

docker run --rm -p 8080:8080 -e JDBC_URL=jdbc:postgresql://${HOST_NAME}:5432/petclinic micronaut-petclinic
Enter fullscreen mode Exit fullscreen mode

Then it takes around 300ms to start. (๑•̀ㅂ•́)و✧

Top comments (0)