Creating a reactive data repository
Earlier in Chapter 3, Querying for Data with Spring Boot, we built an easy-to-read data repository by extending JpaRepository
from Spring Data JPA. For Spring Data R2DBC, let’s write something like this:
public interface EmployeeRepository extends // ReactiveCrudRepository<Employee, Long> {}
This code can be described as follows:
EmployeeRepository
: The name for our Spring Data repository.ReactiveCrudRepository
: Spring Data Commons’ base interface for any reactive repository. Note that this isn’t specific to R2DBC but instead for ANY reactive Spring Data module.Employee
: The domain type for this repository (which we’ll code further in the chapter).Long
: The primary key’s type.
In the previous chapter, we scratched together an Employee
domain type using a Java 17 record. However, to interact with our database, we need something a little more detailed than that...