Java 通过JDBC URL使用TestContainers DB但与@Rule一起使用时出错

Java 通过JDBC URL使用TestContainers DB但与@Rule一起使用时出错,java,postgresql,hibernate,spring-boot,testcontainers,Java,Postgresql,Hibernate,Spring Boot,Testcontainers,我正在尝试使用TestContainers进行集成测试。我开始使用它实例化如下对象: @ClassRule public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer() .withDatabaseName("producto") .withInitScript("init.sql"); 这样我的实体类就可以完美地工作。但是当我试图通过JDB

我正在尝试使用TestContainers进行集成测试。我开始使用它实例化如下对象:

@ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer()
        .withDatabaseName("producto")
        .withInitScript("init.sql");
这样我的实体类就可以完美地工作。但是当我试图通过JDBCURL使用它时,我得到了如下异常

rg.postgresql.util.PSQLException: ERROR: cross-database references are not implemented: "producto.producto.driver"
我正在使用Spring Boot,因此我在application.properties中定义以下属性以利用Spring Boot自动配置(不再在代码中定义容器):

我的实体类定义为:

@Entity
@Table(name = "driver", schema = "producto", catalog = "producto")
public class DriverEntity { }
我真的不明白为什么它在定义对象时起作用,但在使用JDBCURL时却不起作用


是否需要定义其他属性?

从JDBC URL启动时,数据库名称将为“test”(Testcontainers忽略JDBC URL中的数据库名称)

在代码中,您可以硬编码数据库名称,但不建议这样做,因为您可能正在不同的环境中使用不同的数据库名称运行应用程序

尝试从批注中删除数据库名称。

输入错误

org.testcontainers.jdbc.ContainerDatabaseDrive 应该是
org.testcontainers.jdbc.ContainerDatabaseDriver

我也遇到了同样的问题(尽管有不同的错误消息)。你找到解决办法了吗?文档说数据库名被忽略了,但这实际上并不正确
spring.datasource.url=jdbc:tc:postgresql:10.16://somehost:12345/bla?tc_reusible=true
将创建名为“bla”而不是“test”的数据库
@Entity
@Table(name = "driver", schema = "producto", catalog = "producto")
public class DriverEntity { }