Tom*_*Tom 10 spring integration-testing spring-boot testcontainers
为我的集成测试进行以下配置后,我遇到了以下异常:
Driver org.testcontainers.jdbc.ContainerDatabaseDriver claims to not accept jdbcUrl, jdbc:postgresql://localhost:32864/test?loggerLevel=OFF
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = WebApplication.class)
@AutoConfigureMockMvc
@Testcontainers
@TestPropertySource(ResourceUtils.CLASSPATH_URL_PREFIX + "application-test.properties")
public abstract class AbstractIntegrationTest {
@Autowired
protected MockMvc mockMvc;
@Container
protected static PostgreSQLContainer<?> postgresqlContainer = new PostgreSQLContainer<>();
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgresqlContainer::getJdbcUrl);
registry.add("spring.datasource.username", postgresqlContainer::getUsername);
registry.add("spring.datasource.password", postgresqlContainer::getPassword);
}
@Test
void contextLoads() {
Assertions.assertThat(mockMvc).isNotNull();
Assertions.assertThat(postgresqlContainer.isRunning()).isTrue();
}
}
Run Code Online (Sandbox Code Playgroud)
返回
但它应该返回postgresqlContainer.getJdbcUrl()
,它缺少tc部分。jdbc:postgresql://localhost:32864/test?loggerLevel=OFF
jdbc:tc:postgresql://...
有什么办法解决这个问题吗?
对其进行硬编码:String.format("jdbc:tc:postgresql://localhost:%s/%s", postgresqlContainer.getFirstMappedPort(), postgresqlContainer.getDatabaseName())
似乎有效。
我在这里做错了什么?
bsi*_*eup 17
请参阅此处的大橙色警告: https://www.testcontainers.org/modules/databases/jdbc/
tc:
您应该使用带有前缀的JDBC URL和ContainerDatabaseDriver
/或带有原始驱动程序的容器实例getJdbcUrl()
(或者让系统为您检测驱动程序),而不是同时使用两者。
归档时间: |
|
查看次数: |
17928 次 |
最近记录: |