将MySQL连接器版本从5.1.42升级到8.0

时间:2020-07-29 22:55:21

标签: java mysql mysql-connector java-11

此升级将与com.mysql.jdbc.Driver一起使用吗?因为随着驱动程序的更改,即com.mysql.cj.jdbc.Driver引发无法启动容器错误。

ERROR [main] 0].tryStart(264) | Could not start container
org.rnorth.ducttape.TimeoutException: org.rnorth.ducttape.TimeoutException: java.util.concurrent.TimeoutException
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:53)
    at org.testcontainers.containers.JdbcDatabaseContainer.waitUntilContainerStarted(JdbcDatabaseContainer.java:129)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:259)
    at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:212)
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)
    at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:210)
    at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:199)
    at com.nexage.nexus.common.BaseNexus_IT.<clinit>(BaseNexus_IT.java:280)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

在pom.xml中添加了以下依赖项

     <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
        <scope>test</scope>
    </dependency>

在ds.properties文件中

 datasource.name=coreDS
 datasource.driver=com.mysql.cj.jdbc.Driver
 datasource.url=jdbc:mysql://localhost:18082/core?useSSL=false&requireSSL=false&verifyServerCertificate=false&profileSQL=true&maxQuerySizeToLog=16384&serverTimezone=America/New_York
 datasource.username=root
 datasource.password=mysql

启动容器的代码:

公共静态GenericContainer mysqlCore;

    mysqlCore = new MySQLImageContainer(testProperties.get("mysql.docker.image").toString())
            .withUsername(testProperties.get("db.username").toString())
            .withPassword(testProperties.get("db.password").toString())
            .withDatabaseName("core");
    mysqlCore.setPortBindings(Arrays.asList(testProperties.get("mysql.core.db.port").toString() + ":3306/tcp"));

    System.out.println(" starting mysql container");
    mysqlCore.start();

1 个答案:

答案 0 :(得分:0)

通过将测试容器以及新的mysql驱动程序和mysql连接器8.0版本升级到1.14.3可以解决该错误。