如何在春季启动应用中设置GOOGLE_APPLICATION_CREDENTIALS [英] How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app

查看:235
本文介绍了如何在春季启动应用中设置GOOGLE_APPLICATION_CREDENTIALS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Java中使用Google视觉库.这些步骤指定我需要设置身份验证凭据才能开始使用库.我能够从"API控制台凭据"页面生成json属性文件,并将其放置在资源文件夹中的spring boot应用程序中.

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.

我认为已更新了我的application.properties文件,使其包含如下所示的值:

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.

推荐答案

我能够使用Spring Cloud GCP配置此属性spring-cloud-gcp-starter-data-datastore,创建服务帐户项目所有者,复制json主资源目录的私钥,并在application.properties

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

来自文档

这篇关于如何在春季启动应用中设置GOOGLE_APPLICATION_CREDENTIALS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆