Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix timestamp conversion (#2065) Dec 3, 2019
README.adoc URL Cleanup Mar 20, 2019
pom.xml Bump versions post 1.2 release to 1.3 (#2058) Nov 26, 2019


Spring Cloud GCP Cloud Spanner Starter Example

This code sample demonstrates how to read and write POJOs from Google Cloud Spanner using the Spring Data Cloud Spanner module Spring Cloud GCP Cloud Spanner Starter.

Running the example

  1. Create a new Cloud Spanner instance named "spring-demo". The example application will create the database and tables if they do not already exist.

  2. If you are authenticated in the Cloud SDK, your credentials will be automatically found by the Spring Boot Starter for Google Cloud Spanner.

    Alternatively, create a service account from the Google Cloud Console and download its private key.

    Then, uncomment the property in the file and fill its value with the path to your service account private key on your local file system, prepended with file:.

  3. Run the SpannerRepositoryExample or the SpannerTemplateExample Spring Boot console apps. This causes the app to generate sample Trade objects filled with some demo data and persists them to the Cloud Spanner table created earlier. These POJOs are then retrieved and their contents are printed in the browser.

    1. To run the SpannerRepositoryExample:

      `mvn spring-boot:run`
    2. To run the SpannerTemplateExample:

      `mvn spring-boot:run`

Note that the sample application, still running, also provides REST endpoints. For example, you can retrieve all Trade objects in the repository by using curl http://localhost:8080/trades, or any specific trade via curl http://localhost:8080/trades/<trader_id>,<trade_id>;. This is achieved using Spring Data REST and the @RepositoryRestResource annotation.

You can also write trades using curl -XPOST -H"Content-Type: application/json" -d@test.json http://localhost:8080/trades/ where the file test.json holds the JSON representation of a Trade object.

You can’t perform that action at this time.