我正在尝试使用TestContainers进行集成测试。我开始使用它来实例化对象,比如:
@ClassRule
public static PostgreSQLContainer postgres = (PostgreSQLContainer) new PostgreSQLContainer()
.withDatabaseName("producto")
.withInitScript("init.sql");这样,我的实体类就可以完美地工作了。但是,当我尝试通过here描述的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时就不会了。
是否需要定义其他属性?
发布于 2019-02-02 00:06:34
当从JDBC URL启动时,数据库名称将是"test“(Testcontainers忽略JDBC URL中的数据库名称)。
在您的代码中,您硬编码数据库名称,这是不推荐的,因为您可能会在不同的环境中使用不同的数据库名称运行您的应用程序。
尝试从批注中删除数据库名称。
发布于 2019-02-26 08:53:01
打字错误。
org.testcontainers.jdbc.ContainerDatabaseDrive应为org.testcontainers.jdbc.ContainerDatabaseDriver
https://stackoverflow.com/questions/54470759
复制相似问题