I am trying to run my spring application which includes cloud spanner, but application is not starting
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.
I am using following dependency for spanner
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>org.springframework.cloud</groupId>
<version>1.2.8.RELEASE</version>
</dependency>
SpannerTemplate should be auto-configured, as per document – https://googlecloudplatform.github.io/spring-cloud-gcp/reference/html/index.html#spring-data-cloud-spanner
I have included following configurations in application.properties file
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
Can someone please help me to understand why this error is coming and help me to resolve this issue.
As per documentation https://spring.io/projects/spring-cloud-gcp correct dependency should be
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>com.google.cloud</groupId>
</dependency>
and not
<dependency>
<artifactId>spring-cloud-gcp-starter-data-spanner</artifactId>
<groupId>org.springframework.cloud</groupId>
</dependency>
Because : Spring Cloud GCP is no longer part of the Spring Cloud release train. The new repository location is https://github.com/GoogleCloudPlatform/spring-cloud-gcp. If you are upgrading from version 1.x, take a look at the migration guide to upgrade from version 1.x to 2.0.0 (or later).