GraalVM Native Image

What It Is

A native image compiles your Spring Boot app ahead of time (AOT) into a single machine executable. No JVM is needed at runtime.

JVM jarNative image
Startup2 to 5 s0.05 to 0.2 s
Memory (idle)250 to 400 MB50 to 100 MB
Build timesecondsseveral minutes, lots of RAM
Peak throughputbest (JIT optimises at runtime)a bit lower (no JIT)
Reflection / dynamic proxiesjust workneed hints (Spring generates most)

Building One

Example

Add the org.graalvm.buildtools:native-maven-plugin (Spring Initializr adds it when you pick "GraalVM Native Support"), then:

# needs GraalVM JDK 21 installed
./mvnw -Pnative native:compile
./target/shopease

# or build a small container image without installing GraalVM
./mvnw -Pnative spring-boot:build-image

Example output

[shopease:48211]     [7/8] Compiling methods...    (95.3s @ 4.10GB)
Finished generating 'shopease' in 2m 41s.

  .   ____          _            __ _ _
 :: Spring Boot ::                (v3.3.4)
INFO  c.s.ShopEaseApplication : Started ShopEaseApplication in 0.118 seconds (process running for 0.124)

When to Use It

  • Good: serverless (AWS Lambda, Cloud Run scale-to-zero), CLI tools, many small services where memory costs money.
  • Skip: long-running monoliths with heavy load (JVM JIT wins), libraries that use a lot of reflection without hints.
  • A middle option: CDS / AOT cache on the normal JVM (-XX:SharedArchiveFile, Spring Boot 3.3+ supports it) cuts startup by 30 to 50%.