Skip to content

getting started for spring developers

devonfw-core edited this page Dec 13, 2022 · 7 revisions

Getting started with Quarkus for Spring developers

As a Spring developer, you have heard more and more about Quarkus: its pros and cons, its fast growth etc. So, you decided to adopt/try Quarkus for your (next) project(s) and are wondering where to go next and what you need to pay attention to when moving from Spring to Quarkus.

This guide tries to address this exact concern. In the following, we will present you some main points you should be aware of when starting to develop with Quarkus, along with some useful sources.

  1. Quarkus is a fairly new Java toolkit. Thus, it is very well documented. It also provides a set of well-written technical guides that are a good starting point to get in touch and make the first steps with Quarkus. See here. It is an Open Source project licensed under the Apache License version 2.0. The source code is hosted in GitHub. If you have any questions or concerns, don’t hesitate to reach out to the Quarkus community.

  2. Same as Spring Initializr, you can go to code.quarkus.io to create a new application. Also, check out our Template Quarkus Guide to see our recommendations on certain topics.

  3. In Spring stack, we recommend structuring your application into multiple modules, known as our classic structure. Moving to Quarkus and the world of cloud-native microservices, where we build smaller applications compared to monoliths, we recommend keeping everything top-level and simple. Therefore, we propose the modern structure as a better fit.

  4. Quarkus focuses not only on delivering top features, but also on the developer experience. The Quarkus’s Live Coding feature automatically detects changes made to Java files, application configuration, static resources, or even classpath dependency changes and recompiles and redeploys the changes. As that, it solves the problem of traditional Java development workflow, hence improves productivity.

        Write Code → Compile → Deploy → Test Changes/ Refresh Browser/ etc → Repeat (traditional)
        Write Code → Test Changes/ Refresh Browser/ etc → Repeat (Quarkus)

    You can use this feature out of the box without any extra setup by running:

      mvn compile quarkus:dev
    Another highlight feature to speed up developing is the Quarkus’s Dev Mode with Dev Services, which can automatically provision unconfigured services in development and test mode. This means that if you include an extension and don’t configure it, Quarkus will automatically start the relevant service and wire up your application to use it, therefore saving you a lot of time setting up those services manually. In production mode, where the real configuration is provided, Dev Services will be disabled automatically.

    Additionally, you can access the Dev UI at \q\dev in Dev Mode to browse endpoints offered by various extensions, conceptually similar to what a Spring Boot actuator might provide.

  5. Quarkus is made of a small core on which hundreds of extensions rely. In fact, the power of Quarkus is its extension mechanism. Think of these extensions as your project dependencies. You can add it per dependency manager such as maven or gradle.

    mvn quarkus:list-extensions
    mvn quarkus:add-extension -Dextensions="groupId:artifactId"
    (or add it manually to pom.xml)
    # or
    gradle list-extensions
    (add dependency to build.gradle)
    Like Spring Boot, Quarkus also has a vast ecosystem of extensions with commonly-used technologies.
    Table 1. Example of common Quarkus extensions and the Spring Boot Starters with similar functionality (book: Quarkus for Spring Developer)
    Quarkus extension Spring Boot Starter

    quarkus-resteasy-jackson

    spring-boot-starter-web

    spring-boot-starter-webflux

    quarkus-resteasy-reactive-jackson

    spring-boot-starter-web

    spring-boot-starter-webflux

    quarkus-hibernate-orm-panache

    spring-boot-starter-data-jpa

    quarkus-hibernate-orm-rest-datapanache

    spring-boot-starter-data-rest

    quarkus-hibernate-reactive-panache

    spring-boot-starter-data-r2dbc

    quarkus-mongodb-panache

    spring-boot-starter-data-mongodb

    spring-boot-starter-data-mongodb-reactive

    quarkus-hibernate-validator

    spring-boot-starter-validation

    quarkus-qpid-jms

    spring-boot-starter-activemq

    quarkus-artemis-jms

    spring-boot-starter-artemis

    quarkus-cache

    spring-boot-starter-cache

    quarkus-redis-client

    spring-boot-starter-data-redis

    spring-boot-starter-data-redis-reactive

    quarkus-mailer

    spring-boot-starter-mail

    quarkus-quartz

    spring-boot-starter-quartz

    quarkus-oidc

    spring-boot-starter-oauth2-resource-server

    quarkus-oidc-client

    spring-boot-starter-oauth2-client

    quarkus-smallrye-jwt

    spring-boot-starter-security

    A full list of all Quarkus extensions can be found here. Furthermore, you can check out the community extensions hosted by Quarkiverse Hub. Quarkus has some extensions for Spring API as well, which is helpful when migrating from Spring to Quarkus.

    Besides extensions, which are officially maintained by Quarkus team, Quarkus allows adding external libraries too. While extensions can be integrated seamlessly into Quarkus, as they can be processed at build time and be built in native mode with GraalVM, external dependencies might not work out of the box with native compilation. If that is the case, you have to recompile them with the right GraalVM configuration to make them work.

  6. Quarkus' design accounted for native compilation by default. A Quarkus native executable starts much faster and utilizes far less memory than a traditional JVM (see our performace comparision between Spring and Quarkus). To get familiar with building native executable, configuring and running it, please check out our Native Image Guide. Be sure to test your code in both JVM and native mode.

  7. Both Quarkus and Spring include testing frameworks based on JUnit and Mockito. Thus, by design, Quarkus enables test-driven development by detecting affected tests as changes are made and automatically reruns them in background. As that, it gives developer instant feedback, hence improves productivity. To use continuous testing, execute the following command:

    mvn quarkus:dev
  8. For the sake of performance optimization, Quarkus avoids reflection as much as possible, favoring static class binding instead. When building a native executable, it analyzes the call tree and removes all the classes/methods/fields that are not used directly. As a consequence, the elements used via reflection are not part of the call tree so they are dead code eliminated (if not called directly in other cases).

    A common example is the JSON library, which typically use reflection to serialize the objects to JSON. If you use them out of the box, you might encounter some errors in native mode. So, be sure to register the elements for reflection explicitly. A How-to is provided by Quarkus Registering For Reflection with practical program snippets.

A very good read on the topic is the e-book Quarkus for Spring Developers by Red Hat. Another good source for direct hands-on coding tutorial is Katacoda Quarkus for Spring Boot Developers

Clone this wiki locally