How Spring Native Cuts Spring Boot Startup to Under 100ms: A Hands‑On Comparison
This article walks through what Spring Native is, how it uses GraalVM native images to dramatically reduce Spring Boot startup time, and provides a step‑by‑step setup, performance comparison, and troubleshooting tips for building and running native Spring applications.
How long does it take to start a Spring Boot project on your own machine? Usually a few seconds to dozens of seconds. Spring officially introduced Spring Native, claiming startup in as little as 79 ms, which feels almost instantaneous.
What is Spring Native?
Spring Native is a cloud‑native technology that leverages the GraalVM native‑image compiler to build Spring applications into native executables. Compared with the JVM, native images lower startup time, improve peak performance, and reduce memory consumption, making them ideal for microservices, function‑as‑a‑service, containers and Kubernetes.
How does a native image work?
A native image compiles Java code ahead‑of‑time into a standalone executable that contains the application classes, its dependencies, runtime libraries, and statically linked native code from the JDK.
GraalVM describes native images as providing a way to build and run Spring Boot applications with characteristics different from conventional JVM deployments: The output is a native executable that includes your application, a subset of the JDK, and required dependencies. In practice the executable can be packaged as an optimized container image (FROM scratch) that reduces the attack surface and is well‑suited for Kubernetes. Startup is almost instantaneous, delivering peak performance immediately, supporting zero‑scale (serverless) scenarios. Memory consumption is reduced, which is advantageous for systems split into many microservices.
These native Spring apps can be deployed as a single executable without a JVM, offering near‑instant startup (typically under 100 ms) and higher peak performance with lower resource usage, at the cost of longer build times and fewer runtime optimisations.
Getting Started
Environment
MacBook Pro 13‑inch (2017)
macOS Big Sur 11.2
IntelliJ IDEA 2021.2.2 (Ultimate)
OpenJDK 11.0.12
Maven 3.6.3
Docker Desktop 4.0.1
Initialize Project
Use https://start.spring.io/ to generate a Spring Boot project with Maven, Spring Boot 2.5.8 and JDK 11, then add the
spring-nativeand
spring-webdependencies.
After adding the dependencies, download the generated project skeleton.
Run Project
Two ways exist to launch a Spring Native application: (1) build a Docker image with the Maven plugin and run the image, or (2) build a native executable locally and run it directly. The example demonstrates the Docker approach.
Step 1: Build Docker image
<code>$ ./mvnw spring-boot:build-image</code>This process can be lengthy and may fail.
Step 2: Run the image
<code>$ docker run --rm spring-native-demo:0.0.1-SNAPSHOT</code>After executing the command, the application starts instantly.
Performance Comparison
Spring Native
The best measured startup time on the author's machine was 143 ms, which feels instantaneous.
Regular Spring Boot
Typical startup took 2.091 seconds.
Conclusion
On the test machine, Spring Native achieved roughly a 15× speed‑up compared with a normal Spring Boot startup.
FAQ
Problem 1: Maven dependency download fails due to poor network
Configure a Maven mirror, for example:
<code><mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>central</name>
<url>https://maven.aliyun.com/repository/central</url>
</mirror></code>Problem 2: Image build fails with out‑of‑memory error
Increase Docker's memory allocation.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.