Under The Hood
backend springboot Spring Boot 3.x / GraalVM Native Image

Spring Boot 3 AOT Engine & GraalVM Native Image Reflection Hints

Last updated
Prerequisites:
Spring Boot basics
Understanding of JIT vs AOT compilation and reflection
  • spring
  • spring-boot
  • graalvm
  • native-image
  • aot
  • reflection

Read at your depth

The practical view

Spring Boot's AOT engine processes your app at build time and generates the metadata GraalVM Native Image needs: it pre-computes bean definitions, condition evaluations, and registers reflection/classpath hints. The result: a native executable with fast startup and low memory. Build with the Maven plugin: mvn -Pnative native:compile (needs GraalVM + native-image). Startup drops from seconds to milliseconds. Caveats: reflection, proxies, and dynamic features must be known at build time — sometimes you add hints via @RegisterReflectionHint, RuntimeHintsRegistrar, or imports.yaml.

The same idea in other frameworks

react equivalent
N/A — server-side Spring/GraalVM concern.

Legacy vs modern

JVM deployment vs GraalVM native image

A JVM jar starts in seconds and supports runtime reflection; a native image starts in milliseconds but requires all dynamic features to be declared at build time.

before → after
JVM jar deployment
java -jar app.jar  # ❌ OLD: JIT — fast to build, slow to start, high memory
GraalVM native image
./mvnw -Pnative native:compile   # ✅ NEW: AOT + native image build
./target/app   # ✅ NEW: native executable — starts in milliseconds

Interview gotchas

Context

This is the defining native-image concept — interviewers want the closed-world assumption and the hint-generation mechanism, because naive ports of JVM apps fail exactly here.

The mechanical answer

GraalVM Native Image builds with a closed-world assumption: it statically analyzes reachable code and compiles it into the executable; there is no JVM class loader that can find classes at runtime, and reflective lookups (Class.forName, getDeclaredMethod, dynamic proxies) only work for entities explicitly registered at build time. Reflection that isn't hinted fails at runtime with NoSuchMethodError/ClassNotFoundException-style errors. Spring Boot 3's AOT engine mitigates this by running the application context model at build time: it discovers beans, evaluates conditions, and generates RuntimeHints (reflection, resources, serialization, JDK proxies) for everything Spring needs, so the native build includes them. Custom reflection (e.g. a library that reflects over YOUR model classes) must be registered manually — the AOT engine cannot know about arbitrary reflective access.

Trap

The naive answer is 'native image just compiles the jar to a binary'. The closed-world model changes what is possible: no dynamic class loading, no unregistered reflection. Another trap: assuming Spring Boot AOT covers all reflection automatically — it covers Spring's own usage; third-party/reflective libraries need explicit hints. Candidates who describe the closed-world assumption and hint registration show real native-image experience.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.