DEV Community

Cover image for Spring Native: Spring Boot but faster
Antonio Moreno
Antonio Moreno

Posted on

Spring Native: Spring Boot but faster

While you are reading these lines, there are a few hundreds of Spring Boot applications struggling to load a JVM and start.

Yet others are up and running but consuming a huge amount of memory since a JVM needs to be underlying - supporting the application on top.

And adding this latency and resource consumption to a more Cloud Native world is just something that... It's NOT a match!

Some developers just abandoned the idea of using Spring Boot in a world conquered by containers. And they moved far to those battles with Golang. Others stayed with Java, but in another flavour, like Quarkus or Micronaut (i.e. GraalVM powered).

But in March 2021, something happened in the community of Spring Boot users, and that was the release of the beta program of Spring Native.

What it was slow and resource consuming 🚚:

Now is... just awesome 🚀:

Why? Spring Boot applications can be now be compiled using GraalVM. I.e., it can be compiled to native code.

  • Image size for an example project can go from ~170MB to ~60MB
  • RAM memory consumption can go from ~172MB to ~30MB
  • Start-up times can go from 2 seconds to 70 milliseconds

Seems awesome.

I've written a small example that you can take a look and comment on that 🙂

GitHub logo antmordel / bookend

Spring Native Starter App. Spring Boot, just faster.

🚀 Bookend: Spring Native Starter app

  • Example Spring Boot REST application using Spring Native
  • Spring Boot, Java 11, Lombok

Provided a comparison between JVM image build and GraalVM image build.

Using Spring Native 0.067 seconds Execution for Spring Native

Using the JVM 2.112 seconds Execution for Spring on top of the JVM

Get started

Create the image locally

./mvnw clean spring-boot:build-image
Enter fullscreen mode Exit fullscreen mode

Running the just created local image

docker run --rm -p 8080:8080 bookend-native:0.0.1-SNAPSHOT

or just

docker-compose up

And if you are Spanish, I've explained all this in a more multimedia format:

Thanks for reading. I appreciate your comments ❤️.

Top comments (0)