spring-boot - 无法使用全局引用的标识符运行 springboot junit 测试
问题描述
我有一个运行spring.jpa.properties.hibernate.globally_quoted_identifiers=true
. 数据库更改通过 liquibase 管理,应用程序使用 mysql 数据库。问题是,当我尝试运行使用 hsqldb 的 junit 测试时,在进行存储库调用时出现以下异常:
Caused by: java.sql.SQLSyntaxErrorException: unexpected token: in statement
我相信这是因为我们目前没有设置默认模式,所以它在没有模式的情况下运行它,但是 liquibase 在PUBLIC
模式中创建了表。我尝试spring.liquibase.default-schema=SCHEMA
在我的测试属性中设置与我的产品属性相同的模式,但随后 liquibase 得到
liquibase.exception.DatabaseException: invalid schema name: SCHEMA in statement [CREATE TABLE SCHEMA.DATABASECHANGELOGLOCK
因为尚未在 HSQLDB 中创建模式。
添加:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.schema=classpath:test-schema.sql
wheretest-schema.sql
只是CREATE SCHEMA IF NOT EXISTS schema;
让我更进一步,但现在当测试运行时,它会尝试运行一些运行 sql 插入的 liquibase,就像INSERT INTO table
没有附加架构一样,它失败了。不幸的是,这个变更集已经针对实际的应用程序运行,所以我无法真正改变它。
有没有办法在spring.jpa.properties.hibernate.globally_quoted_identifiers=true
不摆脱这些变更集的情况下将模式设置为工作,或者测试只是完全被束缚了?有没有办法让 liquibase 运行 sql 语句并自动为它们使用默认模式?
如果有帮助,这就是我的 application-test.properties 的样子:
spring.datasource.url=jdbc:hsqldb:mem:testdb;
spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.liquibase.url=${spring.datasource.url}
spring.liquibase.change-log=classpath:db/changelog/db.changelog-test.xml
spring.liquibase.user=sa
spring.liquibase.contexts=test
spring.liquibase.password=
spring.liquibase.default-schema=schema
spring.jpa.hibernate.ddl-auto=update
spring.datasource.schema=classpath:test-schema.sql
解决方案
推荐阅读
- c# - EF 在使用 Dapper 库运行查询时拦截调用
- javascript - 子组件从父组件中移除socket.io的事件监听器
- java - 带有 maven-source-plugin 的 maven-jar-plugin 不起作用
- c# - C# 错误:“System.IndexOutOfRangeException:'索引超出了数组的范围。' "
- c++ - 如何使用 libbitcoin 更正签名比特币现金输入?
- javascript - 如果在同一路线中,VueJS 会重新加载
- c# - 如何通过 C# 中的 Slack-App 以用户而非 App 的身份在特定频道中发布带有附件的消息
- javascript - 为什么我的js函数在电脑上不行,在手机上不行?
- java - JDK11之后的WSIMPORT在哪里
- vba - 将 VBA 代码粘贴到 thisOutlookSession 中时 Outlook 挂起