Springboot liquibase Oracle Junit测试案件执行失败

发布于 2025-01-22 15:32:46 字数 398 浏览 5 评论 0 原文

我有一个Springboot应用程序,其中使用Liquibase生成Oracle模式和表。 运行应用程序时,运行良好。

但是,当我尝试运行JUNIT测试案例时,它会在以下错误时失败,

Error creating bean name 'liquibase' defined in class path resource....
Migration failed for change set /db/changelog/....
Reason : liquibase.exception.DatabaseException: Schema "XYZ" not found; SQL statement

数据库中都存在架构和表。

不过,为什么我会遇到这个错误?

请提出任何建议。

I have a SpringBoot application in which i use Liquibase to generate oracle schema and tables.
When i run the application, it runs fine.

But when i try to run the Junit test case, it fails with below error,

Error creating bean name 'liquibase' defined in class path resource....
Migration failed for change set /db/changelog/....
Reason : liquibase.exception.DatabaseException: Schema "XYZ" not found; SQL statement

The schema and tables are all present in the Database.

Still, why do i get this error?

Any suggestions please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2025-01-29 15:32:46

我在媒体上找到了一篇文章,涉及未发现您错误的部分错误。链接:

在步骤3中,文章建议Spring用户在您的资源文件夹中添加文件并将其命名为schema-h2.sql。在文件中,他们给出了此示例:

-- CREATE DATABASE IF NOT EXISTS
CREATE SCHEMA IF NOT EXISTS testdb;

对于第4步,您可以在 *.properties文件中打开初始化模式。这将导致schema-platform.sql文件按预期执行。

spring.datasource.initialization-mode=embedded

到达步骤5时,请确保您的平台名称与 *.sql文件匹配。他们在文章中的屏幕截图中显示的示例如下所示。

# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
#spring.datasource.hikari.maximumPoolSize=8
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE;
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.platform=h2
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.datasource.name=testdb

然后,仔细检查所有模式名称非常匹配,您应该很好。

I found an article on Medium regarding the Schema Not Found part of your error. Link: Fix - Schema Not Found and Why

In step 3, the article recommends spring users add a file in your resource folder and name it schema-h2.sql. Within the file they give this example:

-- CREATE DATABASE IF NOT EXISTS
CREATE SCHEMA IF NOT EXISTS testdb;

For step 4, you turn on your initialization-mode in your *.properties files. This will cause the schema-platform.sql files to be executed as expected.

spring.datasource.initialization-mode=embedded

When you reach step 5, make sure your platform name matches the *.sql file. the example they show in the screenshot in the article is shown below.

# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
#spring.datasource.hikari.maximumPoolSize=8
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE;
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.platform=h2
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.datasource.name=testdb

Then, double check all your schema names match perfectly, and you should be good to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文