GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
428 stars 318 forks source link

Add support for Service Connections with Spring Boot 3.1 #1780

Open eddumelendez opened 1 year ago

eddumelendez commented 1 year ago

Is your feature request related to a problem? Please describe. Spring Boot 3.1 introduces Service Connections which can be used with Testcontainers in order to reduce the boilerplate code to setup Datastore, Firestore, PubSub, Spanner for testing

From:

@Container
private static final SpannerEmulatorContainer spannerEmulator =
    new SpannerEmulatorContainer(
        DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator:1.1.1"));

@DynamicPropertySource
static void emulatorProperties(DynamicPropertyRegistry registry) {
  registry.add(
      "spring.cloud.gcp.spanner.emulator-host", spannerEmulator::getEmulatorGrpcEndpoint);
}

To:

@Container
@ServiceConnection
private static final SpannerEmulatorContainer spannerEmulator =
    new SpannerEmulatorContainer(
        DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator:1.1.1"));

There is also benefits about using it at development time.

Describe the solution you'd like Provide support for Service Connections for Datastore, Firestore, PubSub and Spanner

Describe alternatives you've considered Still using the same approach or implement my own.

Additional context Here you can see what is needed in order to make this happen. I've already contributed to spring boot and also to spring-cloud-gcp. So, I would be glad to contribute if this is accepted.

meltsufin commented 1 year ago

How is this related to: #1245 and #159?

eddumelendez commented 1 year ago

Hi @meltsufin The three of them are about improve the experience but are not strictly related. Although #1245 can benefit from this one. #159 is about properties alignment