How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app

折月煮酒 提交于 2020-07-09 07:51:46

问题


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.

回答1:


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 application.properties

spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json

from the documentation




回答2:


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

export GOOGLE_APPLICATION_CREDENTIALS="/Users/ronnyshibley/Dev/eddress-service-key.json"


来源:https://stackoverflow.com/questions/46921518/how-to-set-google-application-credentials-in-spring-boot-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!