Move R2DBC Docker Compose support into spring-boot-r2dbc

See gh-46094
This commit is contained in:
Phillip Webb 2025-05-19 19:34:03 -07:00 committed by Andy Wilkinson
parent 53910c0a0d
commit 2a26ce187a
58 changed files with 60 additions and 190 deletions

View File

@ -20,6 +20,7 @@ plugins {
id "org.springframework.boot.auto-configuration"
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.deployed"
id "org.springframework.boot.docker-test"
id "org.springframework.boot.optional-dependencies"
}

View File

@ -1,9 +0,0 @@
services:
mongo:
image: '{imageName}'
ports:
- '27017'
environment:
- 'MONGODB_ROOT_USERNAME=root'
- 'MONGODB_ROOT_PASSWORD=secret'
- 'MONGODB_DATABASE=testdb'

View File

@ -1,9 +0,0 @@
services:
mongo:
image: '{imageName}'
ports:
- '27017'
environment:
MONGO_INITDB_ROOT_USERNAME: 'root'
MONGO_INITDB_ROOT_PASSWORD: 'secret'
MONGO_INITDB_DATABASE: 'mydatabase'

View File

@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Docker Compose ClickHouse service connections.
*/
package org.springframework.boot.docker.compose.service.connection.clickhouse;

View File

@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Docker Compose MariaDB service connections.
*/
package org.springframework.boot.docker.compose.service.connection.mariadb;

View File

@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Docker Compose MySQL service connections.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;

View File

@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Docker Compose Postgres service connections.
*/
package org.springframework.boot.docker.compose.service.connection.postgres;

View File

@ -1,21 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Utilities to help when creating
* {@link org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails}.
*/
package org.springframework.boot.docker.compose.service.connection.r2dbc;

View File

@ -1,20 +0,0 @@
/*
* Copyright 2012-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Auto-configuration for Docker Compose MS SQL Server service connections.
*/
package org.springframework.boot.docker.compose.service.connection.sqlserver;

View File

@ -1,14 +1,7 @@
# Connection Details Factories
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.boot.docker.compose.service.connection.clickhouse.ClickHouseR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryLoggingDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryMetricsDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryTracingDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.postgres.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.redis.RedisDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.sqlserver.SqlServerR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.docker.compose.service.connection.zipkin.ZipkinDockerComposeConnectionDetailsFactory

View File

@ -38,6 +38,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-actuator"))
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
optional(project(":spring-boot-project:spring-boot-docker-compose"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-testcontainers"))
optional("io.micrometer:micrometer-core")
@ -57,8 +58,12 @@ dependencies {
dockerTestImplementation(project(":spring-boot-project:spring-boot-jdbc"))
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support-docker"))
dockerTestImplementation(testFixtures(project(":spring-boot-project:spring-boot-docker-compose")))
dockerTestImplementation("org.testcontainers:junit-jupiter")
dockerTestRuntimeOnly("com.clickhouse:clickhouse-r2dbc")
dockerTestRuntimeOnly("com.oracle.database.r2dbc:oracle-r2dbc")
dockerTestRuntimeOnly("io.r2dbc:r2dbc-mssql")
dockerTestRuntimeOnly("org.postgresql:r2dbc-postgresql")
testCompileOnly("com.fasterxml.jackson.core:jackson-annotations")

View File

@ -0,0 +1,6 @@
services:
otlp:
image: '{imageName}'
ports:
- '4317'
- '4318'

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.clickhouse;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.clickhouse;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.r2dbc;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -34,9 +34,8 @@ import org.springframework.util.StringUtils;
* @author Moritz Halbritter
* @author Andy Wilkinson
* @author Phillip Webb
* @since 3.1.0
*/
public class ConnectionFactoryOptionsBuilder {
class ConnectionFactoryOptionsBuilder {
private static final String PARAMETERS_LABEL = "org.springframework.boot.r2dbc.parameters";
@ -49,13 +48,13 @@ public class ConnectionFactoryOptionsBuilder {
* @param driver the driver
* @param containerPort the source container port
*/
public ConnectionFactoryOptionsBuilder(String driver, int containerPort) {
ConnectionFactoryOptionsBuilder(String driver, int containerPort) {
Assert.notNull(driver, "'driver' must not be null");
this.driver = driver;
this.sourcePort = containerPort;
}
public ConnectionFactoryOptions build(RunningService service, String database, String user, String password) {
ConnectionFactoryOptions build(RunningService service, String database, String user, String password) {
Assert.notNull(service, "'service' must not be null");
Assert.notNull(database, "'database' must not be null");
ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions.builder()

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mariadb;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mariadb;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mysql;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mysql;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
/**
* Enumeration of supported Oracle containers.

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.postgres;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.postgres;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
@ -22,7 +22,6 @@ import io.r2dbc.spi.Option;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.sqlserver;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Map;

View File

@ -14,14 +14,13 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.sqlserver;
package org.springframework.boot.r2dbc.docker.compose;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
import org.springframework.boot.r2dbc.autoconfigure.R2dbcConnectionDetails;
/**

View File

@ -15,6 +15,6 @@
*/
/**
* Auto-configuration for Docker Compose MySQL service connections.
* Support for Docker Compose R2DBC service connections.
*/
package org.springframework.boot.docker.compose.service.connection.mysql;
package org.springframework.boot.r2dbc.docker.compose;

View File

@ -1,5 +1,12 @@
# Connection Details Factories
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
org.springframework.boot.r2dbc.docker.compose.ClickHouseR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.MariaDbR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.OracleFreeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.OracleXeR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.docker.compose.SqlServerR2dbcDockerComposeConnectionDetailsFactory,\
org.springframework.boot.r2dbc.testcontainers.ClickHouseR2dbcContainerConnectionDetailsFactory,\
org.springframework.boot.r2dbc.testcontainers.MariaDbR2dbcContainerConnectionDetailsFactory,\
org.springframework.boot.r2dbc.testcontainers.MySqlR2dbcContainerConnectionDetailsFactory,\
@ -8,6 +15,10 @@ org.springframework.boot.r2dbc.testcontainers.OracleXeR2dbcContainerConnectionDe
org.springframework.boot.r2dbc.testcontainers.PostgresR2dbcContainerConnectionDetailsFactory,\
org.springframework.boot.r2dbc.testcontainers.SqlServerR2dbcContainerConnectionDetailsFactory
# Database Initializer Detectors
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
org.springframework.boot.r2dbc.init.R2dbcScriptDatabaseInitializerDetector

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.clickhouse;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.r2dbc;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;
@ -43,7 +43,7 @@ class ConnectionFactoryOptionsBuilderTests {
private ConnectionFactoryOptionsBuilder builder = new ConnectionFactoryOptionsBuilder("mydb", 1234);
@Test
void createWhenDriverProtocolIsNullThrowsException() {
void createWhenDriverIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ConnectionFactoryOptionsBuilder(null, 123))
.withMessage("'driver' must not be null");
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mariadb;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.mysql;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.oracle;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.postgres;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.docker.compose.service.connection.sqlserver;
package org.springframework.boot.r2dbc.docker.compose;
import java.util.Collections;
import java.util.Map;