How Spring Boot 3.0 Adds GraalVM AOT Support: Deep Dive into New Modules

Spring Boot 3.0 introduces built‑in GraalVM AOT support, adding new core, bean, and context modules, aot.factories configuration files, and runtime hints such as HttpMimeTypes and CodecConfigurer, enabling developers to replace spring‑native with native AOT extensions for custom resources and reflection.

Programmer DD
Programmer DD
Programmer DD
How Spring Boot 3.0 Adds GraalVM AOT Support: Deep Dive into New Modules

Today we dive into the source code to examine a major change in Spring Boot 3.0: the addition of GraalVM AOT support.

Spring Core

Spring Framework 6.0 adds three new packages:

GraalVM feature – allows the client to intercept native image generation and run custom initialization code at different stages (the API may change and is not part of the public API).

aot – the core package for Spring AOT infrastructure.

javapoet – a Java API for generating source code.

The javapoet directory contains only package-info.java, which is compiled into the directory and contains Square's open‑source javapoet.

/**
 * Spring's repackaging of JavaPoet
 * (with Spring‑specific utilities; for internal use only).
 */
package org.springframework.javapoet;

The GraalVM feature module is packaged under aot/graalvm.

The resources directory also adds an aot.factories file.

Spring Beans

Support for GraalVM AOT is added to Spring bean factories, creating an aot directory and an aot.factories file.

Spring Context

Application context AOT support is also added.

Other Modules

The three modules above add AOT extension interfaces; other Spring Framework modules only need to define an aot.factories file. An example of such a file (located at spring-web/src/main/resources/META-INF/spring/aot.factories) is shown below:

org.springframework.aot.hint.RuntimeHintsRegistrar= \
org.springframework.http.HttpMimeTypesRuntimeHints,\
org.springframework.http.codec.CodecConfigurerRuntimeHints,\
org.springframework.http.converter.json.JacksonModulesRuntimeHints,\
org.springframework.web.util.WebUtilRuntimeHints

In HttpMimeTypesRuntimeHints the resource pattern org/springframework/http/mime.types is registered:

class HttpMimeTypesRuntimeHints implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
        hints.resources().registerPattern("org/springframework/http/mime.types");
    }
}
CodecConfigurerRuntimeHints

registers the CodecConfigurer.properties resource and reflection hints for codec factories:

class CodecConfigurerRuntimeHints implements RuntimeHintsRegistrar {
    @Override
    public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
        hints.resources().registerPattern("org/springframework/http/codec/CodecConfigurer.properties");
        hints.reflection().registerTypes(
            TypeReference.listOf(DefaultClientCodecConfigurer.class, DefaultServerCodecConfigurer.class),
            typeHint -> typeHint.onReachableType(CodecConfigurerFactory.class)
                .withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
        );
    }
}

The CodecConfigurer.properties file contains default codec implementation class mappings:

# Default CodecConfigurer implementation classes for static Client/ServerCodecConfigurer.create() calls.
# Not meant to be customized by application developers; simply instantiate custom impl classes instead.

org.springframework.http.codec.ClientCodecConfigurer=org.springframework.http.codec.support.DefaultClientCodecConfigurer
org.springframework.http.codec.ServerCodecConfigurer=org.springframework.http.codec.support.DefaultServerCodecConfigurer

Conclusion

Spring Framework 6.0 adds GraalVM AOT support extensions and the aot.factories configuration file, allowing developers to extend support for dependencies that do not natively support GraalVM AOT. When creating a Spring Boot starter, you need to analyze and implement GraalVM AOT support, using aot.factories for custom resources, reflection, etc.

Before Spring Boot 3.0, the spring-native dependency was required for such extensions. Starting with Spring Boot 3.0 and Spring Framework 6.0, the built‑in support can be used directly via custom aot.factories files. Future projects like mica-auto will also support generating aot.factories files via annotations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring BootAoTRuntimeHints
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.