This exercise demonstrates how Spring and Spring Boot developers can use well-known Spring annotations for Spring Data, Web, and Dependency Injection when building Quarkus applications. Spring developers can quickly become productive with Quarkus using existing knowledge and familiarity of these APIs.
Creating a Basic Project
Let's create the basic Quarkus Hello World application and include the necessary spring extensions. This command will create the project:
mvn io.quarkus:quarkus-maven-plugin:1.12.2.Final:create \ -DprojectGroupId=org.acme \ -DprojectArtifactId=fruit-taster \ -Dextensions="spring-data-jpa,spring-web,spring-di,jdbc-postgres,jdbc-h2,agroal" \ -DclassName="org.acme.quickstart.GreetingResource" \ -Dpath="/hello"
This will use the Quarkus Maven Plugin and generate a basic Maven project for you in the fruit-taster subdirectory and include the following extensions to enable Spring annotations and APIs:
- spring-data-jpa - Adds Spring Data annotations, such as
@CrudRepositoryallowing integration with database-backed JPA repositories
- spring-web - Adds Spring Web annotations, such as
- spring-di - Adds Spring DI annotations, such as
- jdbc-postgres - Driver for PostgreSQL database. Keep in mind that this is the JDBC variant. Reactive programmers may be interested in the Reactive Postgres Client.
- jdbc-h2 - Alsos the use of the h2 database for local development
Starting the Application
mvn compile quarkus:dev
This application currently does not use any of the Spring annotations. In the next few steps, we'll add those. We won't need to restart the running application because of Quarkus' ability to recompile code on the fly.