未找到 GCP 凭据错误导致应用程序从 2 更新到 Spring 3 后无法启动

问题描述 投票:0回答:1

我刚刚从 spring 2 -> 3 升级了我的应用程序,从那时起我收到了与 Pub/Sub 和凭证相关的错误。我尝试在映像构建过程中添加服务帐户,但这也不起作用。


#pubsub
spring.cloud.gcp.project-id=qzf-product-play-13cf
spring.cloud.gcp.pubsub.emulator-host=localhost:8681
spring.cloud.gcp.credentials.location=classpath:test.json
spring.cloud.gcp.project-id=local-project

然后我看看它是否在主方法中拾取文件,它是

public static void main(final String[] args) {
    String credentialsLocation = "classpath:test.json";
    System.out.println("Trying to load credentials from: " + credentialsLocation);

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
  <version>3.5.4</version>
</dependency>

错误

{"timestamp":"2024-05-14T06:21:54.56208905Z","@version":"1","msg":"Could not create publisher.","logger_name":"product.tt.serviceconfig.pubsub.AbstractEntityPublisher","thread_name":"main","severity":"ERROR","level_value":40000,"stack_trace":"java.io.IOException: Your default credentials were not found. To set up Application Default Credentials for your environment, see https://cloud.google.com/docs/authentication/external/set-up-adc.\n\tat com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:127)\n\tat com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:129)\n\tat com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:101)\n\tat com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:70)\n\tat com.google.api.gax.rpc.ClientContext.create(ClientContext.java:168)\n\tat com.google.cloud.pubsub.v1.stub.GrpcPublisherStub.create(GrpcPublisherStub.java:203)\n\tat com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:201)\n\tat com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:91)\n\tat com.google.cloud.pubsub.v1.Publisher$Builder.build(Publisher.java:881)

我不知道还能尝试什么。我已经这样做了四天了,但无法解决这个错误。

如有任何建议,我们将不胜感激。

spring-boot spring-data-jpa
1个回答
0
投票

我认为您当前版本的 spring-cloud-gcp-starter-pubsub 与 Spring 3 不兼容:https://googlecloudplatform.github.io/spring-cloud-gcp/5.2.1/reference/html/ index.html#compatibility-with-spring-project-versions

也许升级一下,看看是否能解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.