Spring / Spring Boot 4 Basics Interview Questions
How does Spring Boot 4 support GraalVM native images?
Spring Boot 4 has first-class support for compiling applications to GraalVM native images -- ahead-of-time compiled binaries that start in milliseconds and use a fraction of the heap compared to JVM-based deployments. Boot 4 requires GraalVM native-image 25 or later.
# Requirements for native image in Spring Boot 4: # 1. GraalVM native-image 25 (or later) # 2. java.version >= 17 # 3. spring-boot-starter-parent as parent (or spring AOT plugin) # Build native image with Maven: ./mvnw -Pnative native:compile # Output: target/order-service (native binary) # Build native image with Gradle: ./gradlew nativeCompile # Output: build/native/nativeCompile/order-service # Build Docker image with native binary (Buildpacks): ./mvnw spring-boot:build-image -Pnative # Creates a container image using Cloud Native Buildpacks // Native image hints for reflection (when AOT analysis misses something): @ImportRuntimeHints(MyRuntimeHints.class) @SpringBootApplication public class App { ... } public class MyRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader cl) { // Register class for reflection: hints.reflection() .registerType(MyDynamicClass.class, MemberCategory.INVOKE_DECLARED_METHODS); // Register resource file: hints.resources().registerPattern("templates/*.html"); } } # Native image startup comparison: # JVM mode: ~2-4 seconds startup, ~256MB heap # Native mode: ~50-100ms startup, ~50MB memory # Trade-off: Build time 5-10 minutes; no JIT optimisation at runtime
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
