我正在尝试使用 TestContainers 进行集成测试。我开始使用它来实例化对象,例如:
@ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer()
.withDatabaseName("producto")
.withInitScript("init.sql");
这样我的实体类就可以完美地工作了。但是当我尝试通过此处描述的 JDBC URL 使用它时,出现以下异常
rg.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "producto.producto.driver"
我正在使用 Spring Boot,因此我在 application.properties 中定义了以下属性以利用 Spring Boot 自动配置(不再在代码中定义容器):
spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDrive
spring.datasource.url=jdbc:tc:postgresql://somehostname:someport/producto?TC_INITSCRIPT=init.sql
我的实体类定义为:
@Entity
@Table(name = "driver", schema = "producto", catalog = "producto")
public class DriverEntity { }
我真的不明白为什么它在定义对象时起作用,但在使用 jdbc url 时不起作用。
¿ 我需要定义其他属性吗?