问题描述
我正在尝试执行以下操作;
但使用 org.testcontainers.containers.MysqLR2DBCDatabaseContainer
谁能告诉我如何实现这一目标,因为MysqLR2DBCDatabaseContainer似乎没有以下方法:
- :: getJdbcUrl
- :: getpassword
- :: getUsername
@Testcontainers
@SpringBoottest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ApplicationIT {
@Container
public static PostgresqlContainer postgresqlContainer = new PostgresqlContainer()
.withPassword("inmemory")
.withUsername("inmemory");
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url",postgresqlContainer::getJdbcUrl);
registry.add("spring.datasource.password",postgresqlContainer::getpassword);
registry.add("spring.datasource.username",postgresqlContainer::getUsername);
}
@Test
public void contextLoads() {
}
}
解决方法
我有一些测试容器的例子。
-
通过R2dbc网址启动约束器,请参见this R2dbc MySQL example。
-
使用Junit进行手动设置,请参见this R2dbc PostgresSQL example。
-
使用spring初始值设定项类初始化Container,请参见this Neo4j Rx example。