Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Spring Boot 3 how to benefit from Spring AOT with a regular JVM application?

Spring Boot 3 will release in November 2022. The release candidate 2 has already been released.

Spring Boot 3 will ship with Spring AOT. Spring AOT generates additional source code so that reflection calls will be avoided.

Spring AOT was introduced to generate GraalVM Native Images. However, in theory Spring AOT could also be used for regular JVM applications to speed up the start-up process (since regular calls should be faster than reflection calls).

Unfortunately, I didn't find anything about how to use Spring AOT for regular JVM applications in the Spring Boot 3 reference documentation. Do you know how I can profit from Spring AOT in a regular JVM application?

like image 896
Harold L. Brown Avatar asked Dec 19 '25 03:12

Harold L. Brown


2 Answers

This document descibes how to run AOT code on the JRE.

Essentially, you have to build your jar like this

mvn clean compile spring-boot:process-aot package

and run it like this

java -DspringAot=true -jar your-application.jar

like image 67
schrom Avatar answered Dec 21 '25 16:12

schrom


Now it is possible to run Spring applications in Ahead-of-Time mode:

For Gradle, you need to ensure that your build includes the org.springframework.boot.aot plugin.

When the JAR has been built, run it with spring.aot.enabled system property set to true. For example:

$ java -Dspring.aot.enabled=true -jar myapplication.jar

........ Starting AOT-processed MyApplication ...
like image 43
Harold L. Brown Avatar answered Dec 21 '25 17:12

Harold L. Brown