目前,我正在使用 Testcontainer 在 Spring Boot 中實作資料庫的集成測驗。如何使用 application.yml 初始化 Testcontainer。我不想使用@DynamicPropertySource。
public static PostgreSQLContainer container = new PostgreSQLContainer("postgres:12")
spring:
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/db
username: user
password: password
uj5u.com熱心網友回復:
您可以簡單地將 tc 添加到您的 spring.datasource.url 屬性中。
spring:
datasource:
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:postgresql:12:///db?TC_TMPFS=/testtmpfs:rw
username: user
password: password
我不喜歡使用 application.yaml 只是創建 application-test.yaml 并覆寫默認值。您可以查看https://www.testcontainers.org/modules/databases/jdbc/。
您也可以使用 @testpropertysource 注釋覆寫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/451113.html
