Spring Hibernate Liquibase集成测试失败

时间:2019-10-17 17:59:09

标签: hibernate spring-boot liquibase

我可以使用liquibase正确运行我的应用程序。我们使用的环境包括spring,hibernate和mysql。当我尝试运行集成测试(具有h2 db)时,出现此异常:

 Caused by: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcSQLException: Schema "pbr_tenant" not found; SQL statement: Caused by: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcSQLException: Schema "pbr_tenant" not found; SQL statement: SET SCHEMA pbr_tenant [90079-197]
            at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:307)
            at org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$DataSourceClosingSpringLiquibase.afterPropertiesSet(LiquibaseAutoConfiguration.java:218)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1803)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1740)
            ... 105 more Caused by: org.h2.jdbc.JdbcSQLException: Schema "pbr_tenant" not found; SQL statement: SET SCHEMA pbr_tenant [90079-197]

这是我用于集成测试的application.yml的样子。

datasource:
  url: jdbc:h2:mem:data_import-int;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL
  platform: h2
  username: sa
  password:
  driverClassName: org.h2.Driver
jpa:
  database-platform: org.hibernate.dialect.H2Dialect
  properties:
    hibernate:
      show_sql: true
      use_sql_comments: true
      format_sql: true


 liquibase:
      url: jdbc:h2:mem:pbr_tenant;MODE=Mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;INIT=CREATE SCHEMA IF NOT EXISTS pbr_tenant;SCHEMA=pbr_tenant
      contexts: integration-test
      parameters:
        schema: pbr-tenant
      change-log: classpath:db/changelog/fini-changelog.yml

解决办法。

1 个答案:

答案 0 :(得分:1)

所以您似乎缺少架构。尝试以下。

datasource:
  url: jdbc:h2:mem:data_import-int;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS pbr_tenant;MODE=MySQL
  platform: h2
  username: sa
  password:
  driverClassName: org.h2.Driver

以便能够创建模式(如果不存在)。 您也可以尝试:

datasource:
  url: jdbc:h2:mem:data_import-int;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS pbr_tenant;SET SCHEMA pbr_tenant;MODE=MySQL
  platform: h2
  username: sa
  password:
  driverClassName: org.h2.Driver

要另外选择该模式