Used version: Spring Boot 2.4.1
I'm using a MariaDB test container from the Testcontainers project. They say in the JDBC documentation:
For Spring Boot (Before version 2.3.0) you need to specify the driver manually spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver
It seems as if this also true for Spring Boot 2.4.x. Without specifying this driver I get the following exception when starting a test:
Driver org.mariadb.jdbc.Driver claims to not accept jdbcUrl, jdbc:tc:mariadb:10.4.16://localhost/mydb
Setting the driver to org.testcontainers.jdbc.ContainerDatabaseDriver
works.
I opened this issue in their project, but it was closed due to a possible regression in Spring Boot.
Comment From: wilkinsona
I can't reproduce the behaviour you've described. Using 2.4.2 and spring.datasource.url=jdbc:tc:mariadb:10.4.16://localhost/mydb
, the following output is generated upon retrieving a connection from the auto-configured DataSource
:
2021-02-14 13:19:32.680 INFO 46721 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-02-14 13:19:32.740 INFO 46721 --- [ main] o.t.d.DockerClientProviderStrategy : Loaded org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy from ~/.testcontainers.properties, will try it first
2021-02-14 13:20:03.055 INFO 46721 --- [ main] .t.d.DockerMachineClientProviderStrategy : docker-machine executable was not found on PATH (…)
2021-02-14 13:20:32.937 INFO 46721 --- [ main] o.t.d.DockerClientProviderStrategy : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
2021-02-14 13:20:32.940 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : Docker host IP address is localhost
2021-02-14 13:20:32.969 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : Connected to docker:
Server Version: 19.03.12
API Version: 1.40
Operating System: Docker Desktop
Total Memory: 1990 MB
2021-02-14 13:20:32.971 INFO 46721 --- [ main] o.t.utility.ImageNameSubstitutor : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
2021-02-14 13:20:33.118 INFO 46721 --- [ main] o.t.utility.RegistryAuthLocator : Credential helper/store (docker-credential-desktop) does not have credentials for index.docker.io
2021-02-14 13:20:33.639 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
2021-02-14 13:20:33.640 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : Checking the system...
2021-02-14 13:20:33.640 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker server version should be at least 1.6.0
2021-02-14 13:20:33.722 INFO 46721 --- [ main] org.testcontainers.DockerClientFactory : ✔︎ Docker environment should have more than 2GB free disk space
2021-02-14 13:20:34.151 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Pulling docker image: mariadb:10.4.16. Please be patient; this may take some time but only needs to be done once.
2021-02-14 13:20:35.693 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Starting to pull image
2021-02-14 13:20:35.713 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 0 pending, 0 downloaded, 0 extracted, (0 bytes/0 bytes)
2021-02-14 13:20:36.832 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 12 pending, 1 downloaded, 0 extracted, (162 bytes/? MB)
2021-02-14 13:20:36.898 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 11 pending, 2 downloaded, 0 extracted, (1009 bytes/? MB)
2021-02-14 13:20:38.453 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 10 pending, 3 downloaded, 0 extracted, (4 MB/? MB)
2021-02-14 13:20:42.446 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 9 pending, 4 downloaded, 0 extracted, (18 MB/? MB)
2021-02-14 13:20:43.158 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 8 pending, 5 downloaded, 0 extracted, (22 MB/? MB)
2021-02-14 13:20:47.767 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 7 pending, 6 downloaded, 0 extracted, (30 MB/? MB)
2021-02-14 13:20:48.748 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 6 pending, 7 downloaded, 0 extracted, (30 MB/? MB)
2021-02-14 13:20:50.532 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 5 pending, 8 downloaded, 0 extracted, (31 MB/? MB)
2021-02-14 13:20:51.233 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 4 pending, 9 downloaded, 0 extracted, (31 MB/? MB)
2021-02-14 13:20:53.143 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 3 pending, 10 downloaded, 0 extracted, (31 MB/? MB)
2021-02-14 13:20:54.368 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 2 pending, 11 downloaded, 0 extracted, (36 MB/? MB)
2021-02-14 13:20:56.930 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 0 extracted, (47 MB/? MB)
2021-02-14 13:20:57.712 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 1 extracted, (48 MB/? MB)
2021-02-14 13:20:57.771 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 2 extracted, (48 MB/? MB)
2021-02-14 13:20:57.832 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 3 extracted, (48 MB/? MB)
2021-02-14 13:20:57.902 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 4 extracted, (48 MB/? MB)
2021-02-14 13:20:58.085 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 5 extracted, (49 MB/? MB)
2021-02-14 13:20:58.166 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 6 extracted, (49 MB/? MB)
2021-02-14 13:20:58.225 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 7 extracted, (49 MB/? MB)
2021-02-14 13:20:58.469 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 8 extracted, (50 MB/? MB)
2021-02-14 13:20:58.532 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 9 extracted, (50 MB/? MB)
2021-02-14 13:20:58.593 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 1 pending, 12 downloaded, 10 extracted, (50 MB/? MB)
2021-02-14 13:21:22.188 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 0 pending, 13 downloaded, 10 extracted, (119 MB/119 MB)
2021-02-14 13:21:24.581 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 0 pending, 13 downloaded, 11 extracted, (119 MB/119 MB)
2021-02-14 13:21:24.634 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 0 pending, 13 downloaded, 12 extracted, (119 MB/119 MB)
2021-02-14 13:21:24.695 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pulling image layers: 0 pending, 13 downloaded, 13 extracted, (119 MB/119 MB)
2021-02-14 13:21:24.701 INFO 46721 --- [tream-202217782] 🐳 [mariadb:10.4.16] : Pull complete. 13 layers, pulled in 49s (downloaded 119 MB at 2 MB/s)
2021-02-14 13:21:24.711 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Creating container for image: mariadb:10.4.16
2021-02-14 13:21:24.945 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Starting container with ID: ef9b8107b35720961367a0e4dcc3f06cfa6fa64bf499d9213961564a9e18d8c2
2021-02-14 13:21:25.154 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Container mariadb:10.4.16 is starting: ef9b8107b35720961367a0e4dcc3f06cfa6fa64bf499d9213961564a9e18d8c2
2021-02-14 13:21:25.162 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Waiting for database connection to become available at jdbc:mariadb://localhost:32769/mydb using query 'SELECT 1'
2021-02-14 13:21:33.101 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Container is started (JDBC URL: jdbc:mariadb://localhost:32769/mydb)
2021-02-14 13:21:33.101 INFO 46721 --- [ main] 🐳 [mariadb:10.4.16] : Container mariadb:10.4.16 started in PT59.37654S
2021-02-14 13:21:33.113 INFO 46721 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: straurob
Thanks, @wilkinsona for your reply. I created the following repo which only contains the dependencies, a contextLoads()
test and the src/test/resources/application.yml
. I hope this is sufficient.
https://github.com/straurob/spring-boot-testcontainers
Comment From: bsideup
driver-class-name: org.mariadb.jdbc.Driver # this does not work
And this won't work, because you're explicitly forcing the wrong driver. Just don't specify the driver and Spring Boot will select the correct one.
Comment From: straurob
Just don't specify the driver and Spring Boot will select the correct one.
Sometimes, things are too simple. As mentioned by @bsideup, just leaving out the driver works out of the box. Thanks.