Exploring an alternative to Spring Boot

Michiel Blijleven
Techspiration
Published in
3 min readDec 11, 2020

Spring Boot vs Quarkus

Nowadays Spring Boot is a defacto standard within Java development . It is hard to find any java related job opportunity where Spring Boot is not on the requirements list. However, I wondered what alternatives are out there, I mean a Java framework without an alternative is unheard of.

While strolling around the internet I came across Quarkus, which sounded interesting, so I decided to compare the getting started application from both projects and see how they compare.

The goal is to have a simple webservices running in a Docker container.

SBT

Create the simple webservice

Started by using the Spring Boot intializr.
Added only the “Spring Web” dependency
Unzip the created zip file to a directory

mvn clean install
mvn spring-boot:run

SUCCES!

Containerise

vim Dockerfile
FROM openjdk:11-jre-slim
COPY target/*.jar demo.jar
ENTRYPOINT [“java”,”-jar”,”/demo.jar”]
docker build -t sbt/demo .
docker run -p 8080:8080 sbt/demo:latest

Started DemoApplication in 5.117 seconds (JVM running for 6.224)

Quarkus

Quarkus uses a mvn archetype for creating the default project.
mvn io.quarkus:quarkus-maven-plugin:1.8.0.Final:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=getting-started \
-DclassName=”org.acme.getting.started.GreetingResource” \
-Dpath=”/hello”

Problem: the mvn version has to be >3.6.2 the default ubuntu mvn version is 3.6.0 so I upgraded mvn to latest version

Run the previous command again and now it works

Made a small modification to the application to make it behave identically to the sbt implementation

mvn clean install
mvn quarkus:dev

SUCCES!

Containerise

The Quarkus container process can be customised using properties, here you can find the complete list

There are thee options for building your container jib, docker, s2i. in short:

  • jib: will automatically add all files in target/libs to a layer in your docker image
  • docker: uses that docker binary and the Dockerfiles stored in src/main/docker
  • s2i: uses S2I binary builds, for use in OpenShift cluster.

Read all about it here

mvn quarkus:add-extension -Dextensions=”container-image-docker”
mvn clean package -Dquarkus.container-image.build=true -Dquarkus.container-image.group=quarkus
docker run -p 8081:8080 quarkus/getting-started:1.0-SNAPSHOT

2020–09–18 12:56:59,110 INFO [io.quarkus] (main) getting-started 1.0-SNAPSHOT on JVM (powered by Quarkus 1.8.0.Final) started in 1.863s. Listening on: http://0.0.0.0:8080

Comparison

Docker-image

If you compare the start-up times, the Quarkus image starts much faster. 1.863 s vs 5.117. I started both containers multiple times and this 5 second difference is pretty consistant.

The Quarkus image is a lot bigger then the SBT one.
For sbt I used the openjdk:11-jre-slim as a base image quarkus uses ubi-minimal:8.1 from red-hat. Which is actually smaller then the openjdk:11-jre-slim. The Quarkus jar is smaller than the sbt jar.

After connecting to the running containers, I see that the jdk used is a bit bigger and the image used by Quarkus is less optimised. The default Quarkus dockerfile installs a number of libraries and applications, which propably account for the size difference.

Unit testing

Basically the same, biggest difference is that Quarkus provides an initial test case.

SBT

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

No default test implementation

Quarkus

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

Default test is implemented.

rest framework used

quarkus-resteasy: JAX-RS
spring-starter-web: Spring MVC

Personally I feel the jax-rs annotations are cleaner, but of course you can use those in SBT by just using spring-starter-jersey

Conclusion

I started of with the question if there was an alternative to Spring Boot and although I want to dive deeper into the subject, my preliminary conclusion is yes and it is pretty good. Next things I would likely try is adding a datalayer or making a complete (reactive) application.

Would I choose to use Quarkus in my next project? I think I might. Especially if I am going to be creating a reactive application, since this is what Quarkus is actually aimed at.

However the quick start-up time really is a selling point for me..

This blog was originally published on https://techspire.nl/blogs/

--

--

Michiel Blijleven
Techspiration

I am a software engineer and teamlead for the backend team at Techspire. I have been working in IT for about 20 years.