Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app

I am attempting to use the google vision library in java. The steps specify that I need to setup my auth credentials in order to start using the this library . I was able to generate my json property file from API Console Credentials page and I placed it in my spring boot app in the resources folder.

I think updated my application.properties file to include the value like so:

GOOGLE_APPLICATION_CREDENTIALS=datg-avatar-generator-9dc9155cd5bd.json

I'm also setting my property source in my controller like so:

@PropertySource("${GOOGLE_APPLICATION_CREDENTIALS}")

However, after doing that I'm still getting an error saying:

java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
like image 321
DanielD Avatar asked Oct 24 '17 23:10

DanielD


2 Answers

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.

From the projects list, select Manage all projects. The names and IDs for all the projects you're a member of are displayed. You can also select the project go the settings and see the project ID

like image 186
Neill Avatar answered Sep 27 '22 18:09

Neill


You need to set the shell variable. Run this command before mvn run.

export GOOGLE_APPLICATION_CREDENTIALS="/Users/ronnyshibley/Dev/eddress-service-key.json"
like image 24
Ronny Shibley Avatar answered Sep 27 '22 17:09

Ronny Shibley