我試圖從我的 Spring 應(yīng)用程序中讀取 Google-Cloud 存儲(chǔ)中的值。我使用 Spring Cloud GCP 擴(kuò)展來處理 Google Cloud Storage。我的 gcp 依賴項(xiàng)的 Pom.xml:<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-storage</artifactId> <version>1.1.2.RELEASE</version></dependency>當(dāng)我嘗試從我的休息端點(diǎn)讀取文件時(shí),我得到異常(在我的回答結(jié)束時(shí))不知何故我的令牌無法刷新?我在哪里可以設(shè)置我的 clientId 或者還有其他事情發(fā)生?我使用了 pivotal 和 google 提供的示例應(yīng)用程序中的代碼。@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貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
這看起來像是關(guān)于身份驗(yàn)證的問題。您是否遵循了通用的“Spring Cloud GCP Core”[1] 配置?
檢查您的 application.properties [2](或其他配置)并確保它至少包含以下屬性:
spring.cloud.gcp.datastore.project-id=XXX spring.cloud.gcp.datastore.credentials.location=YYY
或選擇 [1] 中顯示的其他方法。

互換的青春
TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
教程中從未提及實(shí)施“Spring Cloud GCP Core”的資源,或者我忽略了它。
我的控制臺(tái)上的 Google Cloud SDK 以某種方式連接了另一個(gè)帳戶。所以我用
gcloud auth application-default login
并登錄正確的帳戶?,F(xiàn)在可以了。謝謝。
添加回答
舉報(bào)
0/150
提交
取消