W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
CredentialsProvider
是一個功能接口,可返回憑據(jù)以認證和授權(quán)對Google Cloud Client庫的調(diào)用。
public interface CredentialsProvider { Credentials getCredentials() throws IOException; }
Spring Cloud GCP啟動器會自動配置CredentialsProvider
。它使用spring.cloud.gcp.credentials.location
屬性找到Google服務(wù)帳戶的OAuth2私鑰。請記住,此屬性是Spring資源,因此可以從許多
不同的位置(
例如文件系統(tǒng),類路徑,URL等)獲取憑證文件。下一個示例在文件系統(tǒng)中指定憑證位置屬性。
spring.cloud.gcp.credentials.location=file:/usr/local/key.json
或者,您可以通過直接指定spring.cloud.gcp.credentials.encoded-key
屬性來設(shè)置憑據(jù)。該值應(yīng)為JSON格式的base64編碼的帳戶私鑰。
如果未通過屬性指定憑據(jù),則啟動程序?qū)L試從許多地方發(fā)現(xiàn)憑據(jù):
GOOGLE_APPLICATION_CREDENTIALS
環(huán)境變量指向的憑據(jù)文件
gcloud auth application-default login
命令提供的憑據(jù)
如果您的應(yīng)用程序在Google App Engine或Google Compute Engine上運行,則在大多數(shù)情況下,您應(yīng)該省略spring.cloud.gcp.credentials.location
屬性,而應(yīng)讓Spring Cloud GCP Starter獲得那些環(huán)境的正確憑據(jù)。在App Engine Standard上,使用
App Identity服務(wù)帳戶憑據(jù)
;在App Engine Flexible上,使用Flexible服務(wù)帳戶憑據(jù);在Google Compute Engine上,使用Compute Engine默認服務(wù)帳戶。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: