【发布时间】:2020-05-23 21:58:34
【问题描述】:
我有一个 SpringBoot 应用程序,我试图在 Testcontainers 的帮助下对其进行测试。我有类似的东西:
@SpringBootTest
public class DummyIT {
@ClassRule
public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer();
static {
postgreSQLContainer.start();
String url = postgreSQLContainer.getJdbcUrl();
}
}
不幸的是,Testcontainers 使用随机端口,如果我理解正确,我们不应该以任何其他方式使用它,这意味着postgreSQLContainer.getJdbcUrl() 的结果不是确定性的。
此外,我的应用程序从其application.properties 检索数据库 url,我的目标是在运行时第一次使用之前,从postgreSQLContainer.getJdbcUrl() 提供的值中替换该值。有没有可能做到这一点?
感谢您的帮助。
【问题讨论】:
标签: java spring-boot testcontainers