我試圖從我的 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條經驗 獲得超8個贊
這看起來像是關于身份驗證的問題。您是否遵循了通用的“Spring Cloud GCP Core”[1] 配置?
檢查您的 application.properties [2](或其他配置)并確保它至少包含以下屬性:
spring.cloud.gcp.datastore.project-id=XXX spring.cloud.gcp.datastore.credentials.location=YYY
或選擇 [1] 中顯示的其他方法。

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