java – How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app
java – How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app
I was able to configure this property using Spring Cloud GCP spring-cloud-gcp-starter-data-datastore, creating a service account project owner, copy the JSON private key to the main resources directory, and setting the following properties in the application.properties
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json
from the documentation
You can find the project id by visiting this page https://support.google.com/googleapi/answer/7014113?hl=en
Go to the API Console.
Setting GOOGLE_APPLICATION_CREDENTIALS for BigQuery Python CLI
From the projects list, select Manage all projects. The names and IDs for all the projects youre a member of are displayed.
You can also select the project go the settings and see the project ID
You need to set the shell variable. Run this command before mvn run.
export GOOGLE_APPLICATION_CREDENTIALS=/Users/ronnyshibley/Dev/eddress-service-key.json
java – How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app
You can use application properties, but you need to use a different StorageOptions builder.
You are probably using
private static Storage storage = StorageOptions.getDefaultInstance().getService();
But if you want to skip the environment variable you need to use:
Credentials credentials = GoogleCredentials
.fromStream(new FileInputStream(path/to/file));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials)
.setProjectId(my-project-id).build().getService();
Note that the default builder (using environment variables) is better if you are going to deploy your applications to cloud, because then this is automatically filled for you.
Related Posts
-
java – Difference between setOnXXX() method and addEventHandler() JavaFx
-
qt – How to close a window in QML/Javascript code (with C++ code involved)?
-
char – Character.getNumericValue(..) in Java returns same number for upper and lower case characters