Spring Native Beta: Building Native Spring Applications with GraalVM
Spring Native Beta introduces Maven and Gradle plugins and native‑configuration annotations that let Spring applications be compiled into GraalVM native images, enabling ultra‑fast startup, low memory usage, and container‑friendly executables for cloud‑native deployments.
The Spring team has announced the Spring Native Beta release, which allows Spring applications to be compiled into GraalVM native images. Spring Native provides Maven and Gradle plugins as well as annotations that help generate optimized native configurations.
Native Spring applications can be packaged as standalone executables that run without a JVM, offering near‑instant startup (typically under 100 ms), peak performance, and reduced memory consumption, while requiring fewer build‑time and runtime optimizations than traditional JVM deployments.
To create a native image, simply run mvn spring-boot:build-image or gradle bootBuildImage . These commands produce an optimized container image that contains a minimal OS layer and a small native executable, bundling only the JDK, Spring, and the application’s required dependencies.
An example container image as small as 50 MB can include Spring Boot, Spring MVC, Jackson, Tomcat, the JDK, and the application itself.
Native execution brings value in many scenarios, such as serverless functions with Spring Cloud, cost‑effective and sustainable hosting of Spring microservices, optimal container images for Kubernetes platforms like VMware Tanzu, and creating the smallest possible container for Spring services.
Spring Native is the result of extensive collaboration across the Spring ecosystem (Spring Framework, Spring Boot, Spring Data, Spring Security, Spring Cloud, Spring Initializr) and the GraalVM team, aiming to improve native‑image compatibility and resource usage.
Although still experimental, the beta version supports a subset of Spring projects. Each Spring Boot 2.x patch release receives a matching Spring Native version (e.g., Spring Native 0.9.0 for Spring Boot 2.4.3). Documentation is provided as HTML or PDF, and a public Javadoc API for native hints is available.
Integration with start.spring.io now includes native support, making it the easiest way to explore native Spring applications.
The Ahead‑of‑Time (AOT) plugins generate native configuration based on annotations. For example, the following code defines a native hint for MySQL drivers:
@NativeHint(
trigger = Driver.class,
options = "--enable-all-security-services",
types = @TypeHint(types = {
FailoverConnectionUrl.class,
FailoverDnsSrvConnectionUrl.class,
// ...
}),
resources = {
@ResourceHint(patterns = "com/mysql/cj/TlsSettings.properties"),
@ResourceHint(patterns = "com/mysql/cj/LocalizedErrorMessages", isBundle = true)
})
public class MySqlHints implements NativeConfiguration {}These hints generate reflect-config.json , resource-config.json , and native-image.properties files automatically. Developers can also annotate their own @Configuration or @SpringBootApplication classes with native hints, such as:
@TypeHint(types = Book.class)
@SpringBootApplication
public class WebClientApplication {
// ...
}The AOT transformation not only benefits native builds but can also improve JVM performance by reducing reflection and resource overhead.
In conclusion, Spring’s native strategy rests on two pillars: making the Spring infrastructure native‑friendly without major changes to existing applications, and collaborating with the GraalVM team to bridge the gap between JVM and native platforms, with ongoing work to enhance native testing and configuration across the broader Java ecosystem.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.