Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Spring Boot 2.7.x #1185

Merged
merged 14 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ on GitHub.

## 3.4.0-SNAPSHOT

**This release officially introduces Spring Boot 2.7 compatibility.**
Note that the previous releases of Spring Cloud GCP 3.x are also compatible with Spring Boot 2.7. The one exception is that if you use Cloud SQL with R2DBC, you'd have to manage the driver versions in your own application dependencies (see [refdoc](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/main/docs/src/main/asciidoc/sql.adoc#r2dbc-support) for details).

### Cloud SQL
- Add version management for the older MySQL and Postgres R2DBC drivers (https://github.com/GoogleCloudPlatform/spring-cloud-gcp/pull/1185).

### Pub/Sub

- Allow Publishers shutdown gracefully
Expand Down
23 changes: 22 additions & 1 deletion docs/src/main/asciidoc/sql.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencies {
}
----

To use PostgreSQL:
To use PostgreSQL with Spring Boot 2.6:

[source,xml]
----
Expand All @@ -129,6 +129,27 @@ dependencies {
}
----

To use PostgreSQL with Spring Boot 2.7 (the latest version of the Postgres R2DBC driver changed its Maven coordinates):

``` xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgres-r2dbc</artifactId>
<exclusions>
<exclusion>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.9.1.RELEASE</version>
</dependency>
```

==== Prerequisites

In order to use the Spring Boot Starters for Google Cloud SQL, the Google Cloud SQL API must be enabled in your GCP project.
Expand Down
23 changes: 22 additions & 1 deletion docs/src/main/md/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ To use MySQL:
implementation("com.google.cloud:spring-cloud-gcp-starter-sql-mysql-r2dbc")
}

To use PostgreSQL:
To use PostgreSQL with Spring Boot 2.6:

``` xml
<dependency>
Expand All @@ -147,6 +147,27 @@ To use PostgreSQL:
implementation("com.google.cloud:spring-cloud-gcp-starter-sql-postgres-r2dbc")
}

To use PostgreSQL with Spring Boot 2.7 (the latest version of the Postgres R2DBC driver changed its Maven coordinates):

``` xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgres-r2dbc</artifactId>
<exclusions>
<exclusion>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.9.1.RELEASE</version>
</dependency>
```

#### Prerequisites

In order to use the Spring Boot Starters for Google Cloud SQL, the
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

<!-- Dependency versions -->
<spring-cloud-dependencies.version>2021.0.4</spring-cloud-dependencies.version>
<spring-boot-dependencies.version>2.6.12</spring-boot-dependencies.version>
<spring-boot-dependencies.version>2.7.4</spring-boot-dependencies.version>
<zipkin-gcp.version>1.0.4</zipkin-gcp.version>
<java-cfenv.version>2.4.1</java-cfenv.version>
<spring-native.version>0.10.5</spring-native.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.FilteredClassLoader;
Expand Down Expand Up @@ -100,18 +103,48 @@ void testSetR2dbcProperty_mySql_urlProvidedByUserIgnored() {
}

@Test
void testSetR2dbcProperty_postgres_defaultUsername() {
void testSetR2dbcProperty_postgres() {
verifyThatCorrectUrlAndUsernameSet(new String[] {"io.r2dbc.postgresql"},
"postgres",
"r2dbc:gcp:postgres://my-project:region:my-instance/my-database");
}

@Test
void testSetR2dbcProperty_mysql() {
verifyThatCorrectUrlAndUsernameSet(new String[] {"dev.miku.r2dbc.mysql"},
"root",
"r2dbc:gcp:mysql://my-project:region:my-instance/my-database");
}

/**
* Verifies that correct database properties got injected into context, given a passed-in list of
* packages to retain on the classpath.
*
* @param driverPackagesToInclude a list of driver packages to keep on the classpath
* @param username expected {@code spring.r2dbc.username} value to verify
* @param url expected {@code spring.r2dbc.username} value to verify
*/
private void verifyThatCorrectUrlAndUsernameSet(
String[] driverPackagesToInclude, String username, String url) {
// Because `FilteredClassLoader` accepts a list of packages to remove from classpath,
// `driverPackagesToInclude` is used to calculate the inverse list of packages to _exclude_.
Set<String> driverPackagesToExclude = new HashSet<>(Arrays.asList(
"dev.miku.r2dbc.mysql",
"io.r2dbc.postgresql"
));
driverPackagesToExclude.removeAll(Arrays.asList(driverPackagesToInclude));

this.contextRunner
.withPropertyValues(
"spring.cloud.gcp.sql.databaseName=my-database",
"spring.cloud.gcp.sql.instanceConnectionName=my-project:region:my-instance")
.withClassLoader(new FilteredClassLoader("dev.miku.r2dbc.mysql"))
.withClassLoader(new FilteredClassLoader(driverPackagesToExclude.toArray(new String[0])))
.run(
context -> {
assertThat(context.getEnvironment().getProperty("spring.r2dbc.url"))
.isEqualTo("r2dbc:gcp:postgres://my-project:region:my-instance/my-database");
.isEqualTo(url);
assertThat(context.getEnvironment().getProperty("spring.r2dbc.username"))
.isEqualTo("postgres");
.isEqualTo(username);
});
}

Expand Down
21 changes: 21 additions & 0 deletions spring-cloud-gcp-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<gcp-libraries-bom.version>26.1.2</gcp-libraries-bom.version>
<cloud-sql-socket-factory.version>1.7.0</cloud-sql-socket-factory.version>
<guava.version>31.1-jre</guava.version>
<r2dbc-mysql-driver.version>0.8.2.RELEASE</r2dbc-mysql-driver.version>
<r2dbc-postgres-driver.version>0.8.12.RELEASE</r2dbc-postgres-driver.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -274,13 +276,32 @@
<version>${cloud-sql-socket-factory.version}</version>
</dependency>

<!-- Spring Boot 2.7 no longer manages this dependency.
Replace with MariaDB driver once it's supported.
https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/990
-->
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<version>${r2dbc-mysql-driver.version}</version>
</dependency>

<!-- spring-cloud-gcp-starter-sql-postgres-r2dbc -->
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>cloud-sql-connector-r2dbc-postgres</artifactId>
<version>${cloud-sql-socket-factory.version}</version>
</dependency>

<!-- Spring Boot 2.7 no longer manages this dependency.
Replace with org.postgres group ID once Spring Boot 2.6 is out of support.
-->
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>${r2dbc-postgres-driver.version}</version>
</dependency>
elefeint marked this conversation as resolved.
Show resolved Hide resolved

<!--Google Cloud Platform Libraries BOM -->
<dependency>
<groupId>com.google.cloud</groupId>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-gcp-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.12</version>
<version>2.7.4</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring.cloud.gcp.sql.instance-connection-name=[YOUR_SQL_INSTANCE_NAME]
# So app starts despite "table already exists" errors.
spring.datasource.continue-on-error=true
# Enforces database initialization
spring.datasource.initialization-mode=always
spring.sql.init.mode=always

spring.jpa.hibernate.ddl-auto=create-drop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring.cloud.gcp.sql.instance-connection-name=[instance-connection-name]
# So app starts despite "table already exists" errors.
spring.datasource.continue-on-error=true
# Enforces database initialization
spring.datasource.initialization-mode=always
spring.sql.init.mode=always

# Leave empty for root, uncomment and fill out if you specified a user
#spring.datasource.username=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ spring.cloud.gcp.sql.instance-connection-name=[instance-connection-name]
# So app starts despite "table already exists" errors.
spring.datasource.continue-on-error=true
# Enforces database initialization
spring.datasource.initialization-mode=always
spring.sql.init.mode=always
#spring.cloud.gcp.project-id=
#spring.cloud.gcp.credentials.location=file:/path/to/service-account.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"spring.datasource.username=postgres",
"spring.datasource.password=test",
"spring.datasource.continue-on-error=true",
"spring.datasource.initialization-mode=always"
"spring.sql.init.mode=always"
})
class SqlPostgresSampleApplicationIntegrationTests {

Expand Down