如何在 Spring Boot 应用程序中设置 GOOGLE_APPLICATION_CREDENTIALS [英] How to set GOOGLE_APPLICATION_CREDENTIALS in spring boot app

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

问题描述

我正在尝试在 Java 中使用谷歌视觉库.这些步骤指定我需要设置我的身份验证凭据才能开始使用 this 图书馆.我能够从 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 the application.properties

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

来自 文档

您可以通过访问此页面找到项目 ID https://support.google.com/googleapi/answer/7014113?hl=zh-CN转到 API 控制台.

You can find the project id by visiting this page https://support.google.com/googleapi/answer/7014113?hl=en Go to the API Console.

从项目列表中,选择管理所有项目.显示您所属的所有项目的名称和 ID.也可以选择项目进入设置查看项目ID

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

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

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