【问题标题】:In Spring Boot 3 how to benefit from Spring AOT with a regular JVM application?In Spring Boot 3 how to benefit from Spring AOT with a regular JVM application?
【发布时间】:2022-12-02 02:24:07
【问题描述】:

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?

【问题讨论】:

    标签: java spring spring-boot ahead-of-time-compile


    【解决方案1】:

    You can run it with :

    java -DspringAot=true -jar myapplication-0.0.1-SNAPSHOT.jar
    

    Also check documentation for :

    AOT runtime modes

    Any application using Spring AOT can use the springAot System property in order to use the AOT classes with a regular JVM. This is mainly useful for debugging purposes in case of issues during native image generation.

    For running an application with gradle bootRun or mvn spring-boot:run, configure your build as following:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <!-- ... -->
            <systemPropertyVariables>
                <springAot>true</springAot>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    

    【讨论】:

    • This is the documentation for the "old" spring-native module. Spring Boot 3 now includes this directly in its Maven plugin (docs.spring.io/spring-boot/docs/3.0.0-RC2/maven-plugin/…). But this lacks the docs on using just AOT without native.
    • I think native generation is possible using mvn spring-boot:process-aot. Regarding the missing documentatiopn - that's probably because it hasn't released properly yet.
    • @dan1st But does a resulting JAR file make use of the generated source files too?
    • Only with -DspringAOT AFAIK
    • @dan1st would there be any advantage to using just AOT in a "normal" Spring Boot JVM app? From my understanding it will just "pre-compute" some of the beans at build time vs. runtime? is it going to speed up application start time WITHOUT all the "limitations" of GraalVM (all the reflection and AspectJ limitations)?
    猜你喜欢
    • 2022-12-19
    • 2022-12-28
    • 2022-11-09
    • 2022-12-02
    • 2022-12-27
    • 2022-11-20
    • 2022-12-02
    • 2022-12-19
    • 2022-12-28
    相关资源
    最近更新 更多