Introduction
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 with 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:2.16.3.Final:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=fruit-taster \
-Dextensions="spring-data-jpa,spring-web,spring-di,jdbc-postgres,jdbc-h2" \
-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
@CrudRepository
allowing integration with database-backed JPA repositories - spring-web - Adds Spring Web annotations, such as
@RestController
,@RequestMapping
,@PathVariable
,@GetMapping
, etc. - spring-di - Adds Spring DI annotations, such as
@Autowired
,@Configuration
,@Component
, etc. - 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
cd fruit-taster
mvn compile quarkus:dev
curl localhost:8080/hello
Hello Spring
Next Steps
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.