Search code examples
javaspringspring-bootahead-of-time-compile

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?


Solution

  • 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 ...