Migrating Spring Boot to Quarkus and GraalVM May 2020
GraalVM enables Serverless by providing much better startup times than Spring Boot. Quarkus is one promising emerging framework in this area. So I migrated one of my Spring Boot Micro Service Backends, namely the storage backend of Noty to Quarkus.
Starting with the results: The big plus certainly is the startup time of the application. The build time of the native compile is not really fun on my Core i7. The resulting binary is big, at least when taking into account what this micro service provides in the end.
Spring Boot | Quarkus (jar compile) | Quarkus (native compile) | |
Startup Time | 11s | 2,1s | 0,5s |
Artefact Size | 43MB (jar) | n/a (no uber-jar created) | 82MB (linux binary) |
Build Time (without tests) | 4,0s | 7,7s | 3min 7s |
The following code changes have been necessary for a successful migration:
- Instead of Spring Boot's RestController I had to migrate to JAX-RS
- Originally Spring Web Security has been used to provide basic authentication, and I had to change to quarkus-elytron-security-properties-file
- Since embedded HSQLDB or H2 are both not supported, at least when compiling a native image, I had to change to Postgres.
- The integration tests are running against a dockerized Postgres now as well
- SpringBootTest has been replaced with QuarkusTest and REST Assured
- Instead of @Value I use @ConfigProperty now. While In the Jar those properties are taken from the environment, with the native compile it seems the build time values are used.
- MapStruct
- Lombok
- Spring's JpaRepositories - Quarkus provides compatibility
- configuration via yaml - instead of property files
- Swagger UI - contained in quarkus-smallrye-openapi
- Validation with Hibernate Validator
Overall it was only a few hours of work to have it up and running again.
Souces available on GitHub: https://github.com/micgn/noty-server-quarkus