连接谷歌云数据存储模拟器

时间:2021-03-22 10:42:05

标签: java google-cloud-datastore spring-cloud

我在我的本地机器上安装了谷歌数据存储模拟器,并编写了一个示例 spring 启动应用程序。 我无法连接数据存储模拟器

这是我的 application.properties 配置

spring.cloud.gcp.datastore.project-id=project-id
spring.cloud.gcp.datastore.emulator.enabled=true
spring.cloud.gcp.datastore.emulator-host=http://localhost:8081

通过这个配置,我会抛出异常

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 个答案:

答案 0 :(得分:0)

使用 Datastore emulator 时,您不需要运行应用程序的凭据,因此 library 可能不知道这一点。

但是,如果您想尝试提供凭据,请在创建服务帐户后,在 shell 中运行以下命令:

export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

KEY_PATH 您必须将其替换为包含您的服务帐户密钥的 JSON 文件的路径。您可以找到更多信息here