The Spring Team has been working on native image support for Spring Applications for quite some time. After 3+ years of incubation in the Spring Native experimental project with Spring Boot 2, native support is moving to General Availability with Spring Framework 6 and Spring Boot 3!
Native images provide almost instant startup time and reduced memory consumption for Java applications. The recent Spring Boot 3.0.0-M5
release marks the first time we’re asking for broader community feedback on our native story. If you need to catch-up on the basics, please refer to the Ahead Of Time basics blog post from late March. You can also learn how to prepare your applications for Spring Boot 3.0.
A lot has happened since March! We’ve improved compatibility with a larger number of use cases and libraries, fixing and improving our native support in the process. This blog post details what you need to know to get started.
Building Your First Native Image
The easiest way to get started is to create a new project from https://start.spring.io. Make sure to select Spring Boot 3.0.0-M5 (or later) and your favorite build tool. Once you’ve done that, one way to build a native image is by using the Native Build Tools plugin and a local GraalVM installation.
Follow the instructions to install GraalVM, or invoke the following if you have SDKMan! installed:
You can check that things are working as expected by making sure native-image
is on your path. Spring Boot has specific integrations for Maven and Gradle. If you’re using Maven, enabling the native profile triggers the necessary infrastructure to build the native image:
For Gradle, our plugin reacts to the presence of the Native Build Tools plugin so we need to apply it:
Once that’s done, this triggers the necessary infrastructure to build the native image:
This generates a native binary for your local OS/CPU located in target/
and build/native/nativeCompile
respectively. You can start your app like with any other binary. For instance with Maven:
Leave A Comment