[英]How do I load properties from application file for Testcontainer?
Currently, I am using Testcontainer to implement integration testing for database in spring boot.目前,我正在使用 Testcontainer 在 spring 引导中实现数据库的集成测试。 How do I init the Testcontainer with the application.yml.
如何使用 application.yml 初始化 Testcontainer。 I don't want to use @DynamicPropertySource.
我不想使用@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
You can simply add tc to you spring.datasource.url property.您可以简单地将 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
I prefer not to use application.yaml just create application-test.yaml and override default one.我不想使用 application.yaml 只是创建 application-test.yaml 并覆盖默认值。 You can check https://www.testcontainers.org/modules/databases/jdbc/ .
您可以查看https://www.testcontainers.org/modules/databases/jdbc/ 。
Also you can override with @testpropertysource annotation.您也可以使用 @testpropertysource 注释覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.