【问题标题】:GCP Dialogflow Java-SpringBoot authentication - Application Default Credentials are not availableGCP Dialogflow Java-SpringBoot 身份验证-应用程序默认凭据不可用
【发布时间】:2021-06-18 14:58:50
【问题描述】:

我需要连接到 GCP Dialogflow 以检测意图。我正在使用 SpringBoot 和 Java 连接到 Dialogflow。此应用程序在 Pivotal Cloud Foundry (PCF) 中运行,我不知道如何在此处设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量。

此处建议的所有解决方案都使用gcloud、Google SDK 或在 Google Compute Engine 中运行的应用。这些解决方案不适用于我的架构。

GoogleCredentials 始终为 null,即使按照以下建议进行设置 -

GoogleCredentials.fromStream(new FileStream("creds.json"));

GoogleCredentials creds = null;
try {
    creds = GoogleCredentials.fromStream(new FileInputStream("creds.json"));
} catch (Exception e) {
    e.printStackTrace();
}

错误 -

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

【问题讨论】:

    标签: spring-boot google-cloud-platform dialogflow-es cloud-foundry


    【解决方案1】:

    经过更多研究,我找到了问题的解决方案。我一直试图在我的 SpringBoot 应用程序中执行此操作。它就在那里,但我之前第一次看到它时并没有多想。

    PCF 中的环境变量可以通过cf CLI 设置。我所要做的就是向管道添加一个额外的命令,并且效果很好 -

    cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE

    来源 - https://cli.cloudfoundry.org/en-US/v6/set-env.html https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html

    附:如果有新应用被推送到 PCF,请在运行上述命令之前进行验证,因为在这种情况下将找不到 APP_NAME。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-06
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2022-01-09
      相关资源
      最近更新 更多