Search code examples
springgraalvm

Compiling Spring Applications to GraalVM Native Images


The GraalVM system apparently cannot compile a Spring application into a native image.

Can we compile a subset of the Spring application -- say, as a separate library -- and then use that with the remainder compiled using the usual javac compiler?

Or maybe if we leave out some Spring features from our application?

Any other possibilities?


Solution

  • A probably more up-to-date answer to this question is provided by the release of Spring Native beta that we (the Spring team) have just announced with a very detailed blog post and a video.

    It allows you to compile Spring applications to a native executable with GraalVM native-image compiler via Spring Boot mvn spring-boot:build-image or gradle bootBuildImage commands, or by just leverage a local native-image installation via the native-image-maven-plugin.

    A Spring Boot application compiled as a native image starting in 38 ms

    The most useful links to use it are start.spring.io which now provides Spring Native support and the getting started section of the reference documentation .

    Spring Native support in available on start.spring.io

    Make sure to configure properly the Spring AOT Maven and Gradle plugins that are mandatory to get proper native support for your Spring application.

    Enjoy!