【发布时间】:2021-03-03 15:46:26
【问题描述】:
我有一个 SpringBoot 应用程序,它使用 H2 内存数据库进行集成测试。如果我在 versino 2.3.4.RELEASE 中使用 SpringBoot,则测试有效。如果我升级到 2.4.0 并出现以下错误,它们会失败:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, jdbc:h2:mem:integrationTestDB;DB_CLOSE_DELAY=-1;MODE=MSSQLServer;INIT=CREATE SCHEMA IF NOT EXISTS dbo\;SET SCHEMA dbo
Caused by: java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, jdbc:h2:mem:integrationTestDB;DB_CLOSE_DELAY=-1;MODE=MSSQLServer;INIT=CREATE SCHEMA IF NOT EXISTS dbo\;SET SCHEMA dbo
这是我的 integration-test.properties,供测试使用:
spring.datasource.url=jdbc:h2:mem:integrationTestDB;\
DB_CLOSE_DELAY=-1;\
MODE=MSSQLServer;\
INIT=CREATE SCHEMA IF NOT EXISTS dbo\\;SET SCHEMA dbo
spring.datasource.driver=org.h2.Driver
spring.datasource.hikari.driver-class-name=org.h2.Driver
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.hbm2ddl.auto=none
spring.datasource.username=sa
spring.datasource.password=
spring.liquibase.user=sa
spring.liquibase.password=
H2 的版本是 1.4.200。 成功与失败的区别在于pom的父元素中的SpringBoot版本:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
</parent>
liquibase 版本从 3.8.9 更改为 3.10.3。我将其配置为保持在 3.8.9,但这没有帮助。
我阅读了发行说明,找到了关于嵌入式数据库检测的部分:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes#embedded-database-detection
但是添加
spring.datasource.initialization-mode=always
属性也没有帮助。
我记得上次找了合适的datasource url花了一些时间,但是用google找不到任何新的线索。
你能给我一个提示,是什么导致了这个问题?
亲切的问候, 乌尔里希
【问题讨论】:
-
这一定是 liquibase 或你的其他配置的问题,因为我可以用你的配置做一个最小的例子。你可以发布你的pom吗?
-
我将发布我的 pom 的精简版。
-
我创建了一个存储库,其中包含我项目的一个非常简化的版本。我离开了基本的库和配置。问题是可以重现的:github.com/UlrichViefhaus/spring-boot-h2-liquibase-example
标签: java sql-server spring-boot h2 liquibase