Some of the changes in Spring 6.0, in addition to some of the dependency package adjustments, it seems like not much change. Today I’ll take you deep into the source code to explore the biggest change - the new Graalvm aot support.
1. Spring core
Spring framework 6.0 has a major change to Spring core with the addition of the following directories.
GraalVM feature
– GraalVM allows clients to intercept native images to generate and run custom code at different stages of initialization. (The GraalVM APi may change at any time, so it was not included in the framework public API)aot
– the core package of Spring AOT infrastructure.javapoet
– Java API package for generating Java source code.
The javapoet directory has only one package-info.java
file, which will be packaged into this directory when compiled, with the contents of the square organization’s open source javapoet.
The GraalVM feature module is also packaged into the aot/graalvm
directory after compilation.
In addition, aot.factories
file has been added to the resolrces
directory.
2. Spring beans
Add Spring bean factories to support graalvm AOT. also add aot
directory and aot.factories
file.
3. Spring context
Add support for application context AOT.
4. Other modules
The above 3 modules add the aot extension interface, the other modules of Spring framework just need to define the aot.factories file.
Let’s take a look at the aot.factories file configuration and content (spring-web\src\main\resources\META-INF\spring\aot.factories
).
Configure the mime.types
resource file in HttpMimeTypesRuntimeHints
.
CodecConfigurerRuntimeHints
configures CodecConfigurer.properties
and the classes configured in it.
|
|
The contents of the CodecConfigurer.properties
file are as follows.
|
|
5. Summary
Spring framework 6.0 added Graalvm aot support extensions and aot.factories
configuration file and specification to complete the extensions for dependencies that do not support Graalvm aot. This requires us to analyze and complete support for Graalvm aot when developing the Spring boot starter. For those that are not supported, such as custom resource files, reflections, etc. use the aot.factories
file for configuration.
Before Spring boot 3.0, we needed to introduce spring-native dependencies to extend support for resource files, reflection, etc. when using Graalvm aot.
After Spring boot 3.0 or Spring framework 6.0 we can use the built-in support of Spring framework 6.0 to handle this directly through custom aot.factories
file configuration.