Exploring Spring Framework 6.0’s New GraalVM AOT Support and Configuration
Spring Framework 6.0 introduces comprehensive GraalVM AOT support, adding new modules such as GraalVM feature, AOT core, and JavaPoet, along with aot.factories configuration files that enable developers to customize native image generation, replace Spring Native, and manage runtime hints for beans, context, and other components.
In the previous article "Spring 6.0 Changes | Spring Boot 3.0 Preview" we introduced some Spring updates. Beyond a few dependency adjustments, today we dive into the most significant change: the new GraalVM AOT support.
1. Spring core
Spring Framework 6.0 adds major changes to Spring core, introducing the following packages:
GraalVM feature – allows client‑side interception of native image generation and execution of custom initialization code at different stages (the GraalVM API may change and is not part of the public framework API).
aot – the core package for Spring AOT infrastructure.
javapoet – a Java API for generating Java source code.
The
javapoetpackage contains only one file,
package-info.java, which is the repackaged Square open‑source JavaPoet library.
<code>/**
* Spring's repackaging of
* <a href="https://github.com/square/javapoet">JavaPoet</a>
* (with Spring‑specific utilities; for internal use only).
*/
package org.springframework.javapoet;
</code>After compilation, the GraalVM feature module is also packaged under
aot/graalvm. Additional resources include the new
aot.factoriesfile.
2. Spring beans
Support for GraalVM AOT is added to Spring bean factories, which also introduces the aot.factories file.
3. Spring context
Application context AOT support is added.
4. Other modules
The three modules above add AOT extension interfaces; other Spring Framework modules only need to define an aot.factories file. Below is an example of such a file (located at spring-web/src/main/resources/META-INF/spring/aot.factories ):
<code>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
</code>The HttpMimeTypesRuntimeHints class registers the mime.types resource file.
<code>class HttpMimeTypesRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
hints.resources().registerPattern("org/springframework/http/mime.types");
}
}
</code>The CodecConfigurerRuntimeHints class registers the CodecConfigurer.properties file and related classes.
<code>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));
}
}
</code>The CodecConfigurer.properties file content:
<code># 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
</code>5. Summary
Spring Framework 6.0 adds GraalVM AOT support extensions and the aot.factories configuration file/specification, enabling developers to extend support for dependencies that do not natively work with GraalVM AOT (e.g., custom resources, reflection) by configuring the aot.factories file. Before Spring Boot 3.0, GraalVM AOT required the spring-native dependency to extend support for resources, reflection, etc. After Spring Boot 3.0 / Spring Framework 6.0, the built‑in support can be used directly by customizing the aot.factories file. In the future, mica-auto will also support generating aot.factories files via annotations.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
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.