Spring Data and R2DBC by Example
Take a look at this tutorial that show you how use R2DBC in a Spring project.
Join the DZone community and get the full member experience.Join For Free
R2DBC is a project that enables us to develop reactive programs API with relational databases, as we can do with databases that natively offer reactive drivers, like for example, Mongo or Cassandra.
Spring Data R2DBC is an abstraction of Spring to use repositories that support R2DBC and allows us a functional approach to interact with a relational database.
I use the following:
- Gradle 6.7.1
- Scala 2.12.6 ( I like this language :) )
- JDK 15
- Intellij IDEA
- Spring Boot 2.4.4
The project structure is:
The Gradle file contains:
The properties files is:
The next class is used to map a row with an object:
The repository is:
The service class is:
The controller class is:
The main class:
The table admin is:
When you run the project, you can call:
Now, we use the curl command to test the service:
Opinions expressed by DZone contributors are their own.