我正在尝试在 java 中使用谷歌视觉库。这些步骤指定我需要设置我的身份验证凭据才能开始使用 this图书馆 。我能够从 API 控制台凭据页面生成我的 json 属性文件,并将其放置在资源文件夹中的 Spring Boot 应用程序中。
我认为更新了我的 application.properties 文件以包含如下值:
GOOGLE_APPLICATION_CREDENTIALS=datg-avatar-generator-9dc9155cd5bd.json
我也在我的 Controller 中设置我的属性源,如下所示:
@PropertySource("${GOOGLE_APPLICATION_CREDENTIALS}")
但是,在这样做之后,我仍然收到一条错误消息:
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 私钥复制到主资源目录,并在应用程序中设置以下属性。特性
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json
来自 documentation您可以通过访问此页面找到项目 ID https://support.google.com/googleapi/answer/7014113?hl=en
转到 API 控制台。
从项目列表中,选择管理所有项目。显示您所属的所有项目的名称和 ID。
您还可以选择项目转到设置并查看项目 ID
关于java - 如何在 Spring Boot 应用程序中设置 GOOGLE_APPLICATION_CREDENTIALS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46921518/