【问题标题】:Liquibase with multi module project具有多模块项目的 Liquibase
【发布时间】:2019-08-22 14:51:58
【问题描述】:

我在项目中有两个模块(integrationTestmain)运行集成测试。我希望在测试本身之前,我的应用程序将使用 liquibase 启动和滚动迁移,但是由于我通过集成测试模块运行应用程序,liquibase 正在寻找有关该模块的主文件,这会导致错误。因为主文件位于带有 miom 应用程序的模块中 (main)

我的项目的结构是这样的(为了紧凑省略了一些类):

PROJECT
└───dataMigration
    │   build.gradle
    │
    └───src
        ├───main
        │   ├───java
        │   │     Application.java
        │   │
        │   └───resources
        │       │   application.yml
        │       │
        │       └───db
        │           └───changelog
        │                   db.changelog-master.xml
        │                   db.changelog-1.0.xml
        │        
        └──integrationTest
               ├───java
               │     IntegrationTest.java
               │
               └───resources
                       application-integration-tests.yml

如果我运行集成测试,则会收到以下错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.xml] (please add changelog or check your Liquibase configuration)

如果我像往常一样运行我的应用程序(来自main 模块),那么一切正常。

如何让应用明白主文件在应用本身所在的模块中,而不是在集成测试模块中?

【问题讨论】:

  • 如何以及在哪里指定 db.changelog-master.xml 的位置?
  • 我在 application-integration-tests.yml 中指定了位置 db.changelog-master.xml 文件
  • change-log: classpath:../../main/resources/db/changelog/db.changelog-master.xml

标签: java spring spring-boot liquibase multi-module


【解决方案1】:

由于您的resources 目录应该是classpath 的一部分,您可以将主变更日志文件位置指定为:

change-log: classpath:db/changelog/db.changelog-master.xml

【讨论】:

  • 是的,在这种情况下。 Liquibase 将在 integrationTest 模块中查找 db.changelog-master.xml 文件
  • 但我需要告诉 liquibase db.changelog-master.xml 在main 模块中
  • 那么你应该确保 src/main/resources 目录包含在类路径中。尝试更改 build.gradle 以包含它。
  • 您可以使用 maven-remote-resources 插件。但是你可能会得到一个:Found X files that match classpath:db/changelog/db.changelog-master.xml 之后的错误。
猜你喜欢
  • 1970-01-01
  • 2020-04-28
  • 2014-08-15
  • 2020-09-13
  • 2019-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-12
相关资源
最近更新 更多