R2DBC is a specification for non-blocking access to relational databases, based on Reactive Streams. Your application can make use of the reactive database connectivity with Cloud Spanner by using the Cloud Spanner R2DBC driver.
Spring Data users should use the Spring Data R2DBC dialect for Cloud Spanner; all other users should bring in the Cloud Spanner R2DBC driver only.
Using the Cloud Spanner R2DBC driver
To add only the Cloud Spanner R2DBC driver to your application, add the following dependency:
<dependency> <groupId>com.google.cloud</groupId> <artifactId>cloud-spanner-r2dbc</artifactId> <version>1.1.0</version> </dependency>
Using the Spring Data R2DBC dialect for Cloud Spanner
For users of the Spring Framework, Spring Data provides familiar abstractions to simplify interaction with common database operations.
To use Spring Data R2DBC features with Cloud Spanner, add the following dependency to your project. The driver is a transitive dependency of the dialect.
<dependency> <groupId>com.google.cloud</groupId> <artifactId>cloud-spanner-spring-data-r2dbc</artifactId> <version>1.1.0</version> </dependency>
A sample application is also available.
Spring Boot configuration
Regardless of which R2DBC dependency you use, if your application is based on Spring Boot, the framework will attempt to automatically configure and provide a connection factory for you.
spring.r2dbc.url property to let autoconfiguration take care of
R2DBC connection factory configuration. The format is shown in the following
- Check out code examples using Cloud Spanner through R2DBC.
- Learn more about R2DBC.
- File a GitHub issue to report a bug or ask a question about Cloud Spanner R2DBC support.