向 Spring Cloud GCP 提供凭据的替代方法

Alternate way of providing Credentials to Spring Cloud GCP

我正在尝试使用 Spring Cloud GCP。我想知道如何以编程方式加载 GCP 凭据,而不是使用 spring.cloud.gcp.credentials.location 从 json 文件加载 GCP 凭据。

创建 com.google.auth.Credentials 类型的 bean 是否能让 Spring-Boot 自动配置 Spring-Cloud-GCP 正确地在应用程序中使用?

如果没有,注入凭据的方式是什么,以便 Spring Cloud GCP 配置正确?

不是 Credentials,而是 CredentialsProvider will take precedence over any properties/autoconfiguration.

类型的 bean

这是一个函数式接口,所以你可以return一个lambda:

        @Bean
        public CredentialsProvider credentialsProvider() {
            return () -> NoCredentialsProvider.create().getCredentials();
        }