我正在尝试运行包含云扳手的 Spring 应用程序,但应用程序未启动
2024-09-24 17:13:12.821 | [main] | ERROR | traceId: | o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Field spannerTemplate in com.sams.payment.common.dbservice.AuthorizationDBService required a bean of type 'org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate' in your configuration.
我正在使用扳手的以下依赖项
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>1.2.8.RELEASE</version>
</dependency>
SpannerTemplate 应根据文档自动配置 - https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#spring-data-cloud-spanner
我已在 application.properties 文件中包含以下配置
spring.cloud.gcp.spanner.enabled=xxxx
spring.cloud.gcp.spanner.instance-id=xxxx
spring.cloud.gcp.spanner.database=xxx
spring.cloud.gcp.spanner.project-id=xxx
spring.cloud.gcp.credentials.location=xxxx
spring.cloud.gcp.spanner.createInterleavedTableDdlOnDeleteCascade=xxxx
有人可以帮助我理解为什么会出现此错误并帮助我解决此问题。
根据文档https://spring.io/projects/spring-cloud-gcp正确的依赖关系应该是
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>com.google.cloud</groupId>
</dependency>
而不是
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>org.springframework.cloud</groupId>
</dependency>
因为:Spring Cloud GCP 不再是 Spring Cloud 发布系列的一部分。新的存储库位置是 https://github.com/GoogleCloudPlatform/spring-cloud-gcp。如果您要从版本 1.x 升级,请查看迁移指南以从版本 1.x 升级到 2.0.0(或更高版本)。