Spring Data R2DBC in Spring Boot application

I introduced you to Spring Data R2DBC. With Spring Boot, configuring and using Spring Data R2DBC is much simpler and more convenient. How is it in detail? Let’s find out together in this tutorial!

First, I will create a Spring Boot project with Spring Data R2DBC Starter and PostgreSQL dependencies as an example.

The result is as follows:

With Spring Boot, to configure the ConnectionFactory object, you just need to use some properties starting with “spring.r2dbc” as follows:

You can also configure the connection pool using the following properties:

Very simple, right?

For Repository classes, you also define them as usual.

For example, I also have a table “student”:

with the following content in the PostgreSQL database:

The model class for the “student” table, I will define it as follows:

The Repository class for the Student model is as follows:

At this point, we have finished configuring Spring Data R2DBC with Spring Boot in our application, guys!

Now, if I run Spring Boot with Java console with the following content:

The result will be as follows:

Add Comment