Quarkus vs Spring Boot: Features and GraalVM native support
Introduction
Quarkus is an open source Java framework developed by Red Hat that supports both OpenJDK HotSpot and GraalVM out of the box. Development of Quarkus started on early 2019, the 1.0.0 version was released on November 2019.
Spring Boot is a very popular open source Java framework that makes it easy to develop standalone Spring based applications with minimal configuration. While Spring was released on 2002, the 1.0.0 version of Spring Boot was released on April 2014.
Features Table
Feature | Quarkus | Spring Boot |
---|---|---|
Dependency injection & components management | CDI, Spring DI extension | Spring Core |
Web / REST API development | JAX-RS, Spring Web extension | Spring MVC, Spring WebFlux, JAX-RS |
Reactive / non-blocking web stack | Vert.x | Reactor Netty |
REST Clients | Vert.x WebClient, MicroProfile Rest Client | RestTemplate, WebClient, Feign |
JSON serialization | JSON-B, Jackson | Jackson, JSON-B |
Simplified data access | Panache, Spring Data JPA extension | Spring Data: JPA, JDBC, MongoDB, LDAP, KeyValue |
Reactive data access | Reactive SQL Clients, Reactive MongoDB Client | Spring Data R2DBC |
Hibernate support | yes | yes |
Authentication & authorization | Elytron Security | Spring Security |
Application monitoring | MicroProfile Health, MicroProfile Metrics | Spring Boot Actuator |
Resilience & Fault tolerance | MicroProfile Fault Tolerance | Netflix Hystrix |
Kubernetes resources generation | yes | no |
GraalVM native images support | yes | experimental |
Kotlin support | yes | yes |
Online project starter | https://code.quarkus.io/ | https://start.spring.io/ |
References
GraalVM native features
Quarkus
Quarkus provides out of the box support for GraalVM native images, and makes it easy to circumvent the limitations of Java native images by applying the following adaptations:
Reflection
By default, the GraalVM removes all the classes/methods/fields that are not used directly in a call tree.
For this reason, it is necessary to manually register the classes that will be manipulated using reflection (such as model/domain classes that require serialization using frameworks that use reflection) either by annotating them with @RegisterForReflection
or using a configuration file when the class cannot be modified (third-party library for example).
Some classes will not be required to be registered for reflection when Quarkus can automatically deduce them at build time by analyzing the code (REST methods for example).
Class initialization
All classes are initialized by default at build time by Quarkus. When a class initialization must be done at runtime, the --initialize-at-run-time=<package or class>
build argument can be used.
Proxy Classes
Proxy classes must be defined at image build time by specifying the list of interfaces that they implement using the build argument -H:DynamicProxyConfigurationResources=<comma-separated-config-resources>
Including resources
Only the web resources found in META-INF/resources
will be included by default in the native executable. To bundle more resources into the native executable, a resources-config.json
configuration file can be used.
Spring Boot
Spring Boot 3
Support to GraalVM Native was added on Spring Boot 3, released on November 24 2022.
Both Maven and Gradle are supported.
In https://start.spring.io/, you can add the GraalVM Native Support
dependency:
Spring Boot 2
The Spring Native experimental project provides GraalVM native-image compilation to Spring Boot 2 applications.
At build time, static analysis of the application is performed to remove the unused parts and do other optimizations. Some code related to initialization will run during this time, including class static initializers. The final executable will contain the initialization state: it will be loaded directly in memory at startup, which makes it quicker to launch the app.
Spring native shares the same limitations as Quarkus native, and requires some configuration for reflection, resources, and dynamic proxies.
References
Conclusion
Both Quarkus and Spring Boot offer a comprehensive stack of technologies and tools to build modern Java applications.
Spring Boot is a more mature framework traditionally used in both monolithic and microservice architectures. Quarkus is more used in cloud and serverless contexts.
While Quarkus is more in line with Java EE standards such as CDI and JAX-RS, Spring provides an alternative modular architecture that revolves around its core container.
Both frameworks support GraalVM native build mode, but Quarkus offers more tools for this integration and is more mature in this regard.
If you are interested by a performance comparison between Quarkus and Spring Boot, check out this article.
Soufiane Sakhi is an AWS Certified Solutions Architect – Associate and a professional full stack developer based in Paris, France. He is the creator of Simply-how.com, the My Route Directions Android app, and many open source browser extensions such as YouTube Playlist Helper and Feedly filtering and sorting.