为了账号安全,请及时绑定邮箱和手机立即绑定

通过尝试从 Googl-Cloud-Storage 读取值来获得无效授权

通过尝试从 Googl-Cloud-Storage 读取值来获得无效授权

浮云间 2023-06-14 16:33:21
我试图从我的 Spring 应用程序中读取 Google-Cloud 存储中的值。我使用 Spring Cloud GCP 扩展来处理 Google Cloud Storage。我的 gcp 依赖项的 Pom.xml:<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-storage</artifactId>  <version>1.1.2.RELEASE</version></dependency>当我尝试从我的休息端点读取文件时,我得到异常(在我的回答结束时)不知何故我的令牌无法刷新?我在哪里可以设置我的 clientId 或者还有其他事情发生?我使用了 pivotal 和 google 提供的示例应用程序中的代码。@RestControllerpublic class GCloudStorageController {    @Value("gs://test_files_test/test.txt")    private Resource gcsFile;    @RequestMapping(value = "/cloud", method = RequestMethod.GET)    public String readGcsFile() throws IOException {        return StreamUtils.copyToString(                this.gcsFile.getInputStream(),                Charset.defaultCharset()) + "\n";    }    @RequestMapping(value = "/cloud", method = RequestMethod.POST)    String writeGcs(@RequestBody String data) throws IOException {        try (OutputStream os = ((WritableResource) this.gcsFile).getOutputStream()) {            os.write(data.getBytes());        }        return "file was updated\n";    }}
查看完整描述

2 回答

?
弑天下

TA贡献1818条经验 获得超7个赞

这看起来像是关于身份验证的问题。您是否遵循了通用的“Spring Cloud GCP Core”[1] 配置?

检查您的 application.properties [2](或其他配置)并确保它至少包含以下属性:

spring.cloud.gcp.datastore.project-id=XXX
spring.cloud.gcp.datastore.credentials.location=YYY

或选择 [1] 中显示的其他方法。

[1] https://cloud.spring.io/spring-cloud-static/spring-cloud-gcp/1.1.2.RELEASE/single/spring-cloud-gcp.html#spring-cloud-gcp-core

[2] https://github.com/spring-cloud/spring-cloud-gcp/blob/master/spring-cloud-gcp-samples/spring-cloud-gcp-data-datastore-sample/src/main/resources/application.properties


查看完整回答
反对 回复 2023-06-14
?
互换的青春

TA贡献1797条经验 获得超6个赞

教程中从未提及实施“Spring Cloud GCP Core”的资源,或者我忽略了它。

我的控制台上的 Google Cloud SDK 以某种方式连接了另一个帐户。所以我用

gcloud auth application-default login

并登录正确的帐户。现在可以了。谢谢。


查看完整回答
反对 回复 2023-06-14
  • 2 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信