This is a sample application which uses the Cloud Spanner client libraries and demonstrates compatibility with GraalVM native image compilation.
The application creates a new Spanner instance and database, and it runs basic operations including queries and Spanner mutations.
-
Follow the GCP Project and GraalVM Setup Instructions.
-
If you wish to run the application against the Spanner emulator, make sure that you have the Google Cloud SDK installed.
In a new terminal window, start the emulator via
gcloud
:gcloud beta emulators spanner start
You may leave the emulator running for now. In the next section, we will run the sample application against the Spanner emulator instsance.
-
Navigate to this directory and compile the application with the GraalVM compiler.
mvn package -P graal
-
(Optional) If you're using the emulator, export the
SPANNER_EMULATOR_HOST
as an environment variable in your terminal.export SPANNER_EMULATOR_HOST=localhost:9010
The Spanner Client Libraries will detect this environment variable and will automatically connect to the emulator instance if this variable is set.
-
Run the application.
./target/com.example.spannersampleapplication
-
The application will run through some basic Spanner operations and log some output statements.
Running the Spanner Sample. Singers Registered in Spanner: Bob Loblaw Virginia Watson