Skip to content

Commit

Permalink
fix: AlloyDB should not load when Postgres starter is used (#2848)
Browse files Browse the repository at this point in the history
Making `alloydb-jdbc-connector` optional dependency in autoconfig module.

Fixes: #2847.
  • Loading branch information
meltsufin committed May 6, 2024
1 parent 891701e commit 2c8e5cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions spring-cloud-gcp-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>alloydb-jdbc-connector</artifactId>
<optional>true</optional>
</dependency>

<!-- Config -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ && isOnClasspath(JDBC_DRIVER_CLASS)) {
environment
.getPropertySources()
.addFirst(new MapPropertySource("ALLOYDB_DATA_SOURCE_URL", primaryMap));
}

// support usage metrics
ConnectorRegistry.addArtifactId(
"spring-cloud-gcp-alloydb/" + this.getClass().getPackage().getImplementationVersion());
// support usage metrics
ConnectorRegistry.addArtifactId(
"spring-cloud-gcp-alloydb/" + this.getClass().getPackage().getImplementationVersion());
}
}

private String getJdbcUrl(AlloyDbProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.ClassUtils;

/** Simple integration test to verify the SQL sample application with Postgres. */
@EnabledIfSystemProperty(named = "it.cloudsql", matches = "true")
Expand Down Expand Up @@ -69,4 +70,10 @@ void testSqlRowsAccess() {
"[jonas@example.com, Jonas, Goncalves]",
"[fejsa@example.com, Ljubomir, Fejsa]");
}

@Test
void testNoAllyDbLoaded() {
assertThat(ClassUtils.isPresent("com.google.cloud.alloydb.SocketFactory", null))
.isFalse();
}
}

0 comments on commit 2c8e5cb

Please sign in to comment.