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");