Quarkus vs Spring Boot: Features and GraalVM native support


Spring Boot vs Quarkus
Learn the differences between the Quarkus framework and Spring Boot: features & library compatibility and the GraalVM native image 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

FeatureQuarkusSpring Boot
Dependency injection & components managementCDI, Spring DI extensionSpring Core
Web / REST API developmentJAX-RS, Spring Web extensionSpring MVC, Spring WebFlux, JAX-RS
Reactive / non-blocking web stackVert.xReactor Netty
REST ClientsVert.x WebClient, MicroProfile Rest ClientRestTemplate, WebClient, Feign
JSON serializationJSON-B, JacksonJackson, JSON-B
Simplified data accessPanache, Spring Data JPA extensionSpring Data: JPA, JDBC, MongoDB, LDAP, KeyValue
Reactive data accessReactive SQL Clients, Reactive MongoDB ClientSpring Data R2DBC
Hibernate supportyesyes
Authentication & authorizationElytron SecuritySpring Security
Application monitoringMicroProfile Health, MicroProfile MetricsSpring Boot Actuator
Resilience & Fault toleranceMicroProfile Fault ToleranceNetflix Hystrix
Kubernetes resources generationyesno
GraalVM native images supportyesexperimental
Kotlin supportyesyes
Online project starterhttps://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 3 - GraalVM Native Support

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.