Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用MySQLContainer设置全局变量_Java_Docker_Testcontainers - Fatal编程技术网

Java 如何使用MySQLContainer设置全局变量

Java 如何使用MySQLContainer设置全局变量,java,docker,testcontainers,Java,Docker,Testcontainers,有一种方法可以设置全局变量:explicit\u defaults\u for\u timestamp=true,使用测试docker容器 我的单元测试中有以下代码: @Container public static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>() .withDatabaseName("test") .withPassword

有一种方法可以设置全局变量:
explicit\u defaults\u for\u timestamp=true
,使用测试docker容器

我的单元测试中有以下代码:

@Container
public static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>()
        .withDatabaseName("test")
        .withPassword("123")
        .withUsername("test")
        .withExposedPorts(3306)
        .withInitScript("database-creation-scripts/mysql-install.sql");

我找不到在MySQLContainer中使用[…]设置全局变量的方法

因为您可以使用以下命令行标志将配置参数传递给MySQL docker容器:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7 --explicit_defaults_for_timestamp
您可以使用“.withCommand()使用Testcontainers对此进行镜像:

@容器
公共静态最终MySQLContainer MySQLContainer=new MySQLContainer()
.withDatabaseName(“测试”)
.withPassword(“123”)
.withUsername(“测试”)
.带外露端口(3306)
.withInitScript(“数据库创建脚本/mysql安装.sql”)
.withCommand(“--explicit\u defaults\u表示时间戳”);
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7 --explicit_defaults_for_timestamp
@Container
public static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>()
        .withDatabaseName("test")
        .withPassword("123")
        .withUsername("test")
        .withExposedPorts(3306)
        .withInitScript("database-creation-scripts/mysql-install.sql")
        .withCommand("--explicit_defaults_for_timestamp");