【问题标题】:liquibase does not run with java -jar SpringBootliquibase 不能与 java -jar SpringBoot 一起运行
【发布时间】:2021-12-28 03:06:27
【问题描述】:

我正在尝试将 liquibase 与现有项目集成。在本地测试 liquibase 时,我一直在使用 IntelliJ,我认为它相当于 mvn spring-boot:run,在这种情况下,当应用程序启动时,liquibase 会运行更新并检查所有更改日志是否已完成。

当我编译成一个 jar (mvn clean install) 并运行 java -jar app.jar liquibase 时,会简单地打印出来:

 15:17:08.769 [main] INFO  liquibase.lockservice - Successfully acquired change log lock
 15:17:09.013 [main] INFO  liquibase.changelog - Creating database history table with name: "app".databasechangelog
 15:17:09.028 [main] INFO  liquibase.changelog - Reading from "app".databasechangelog
 15:17:09.078 [main] INFO  liquibase.lockservice - Successfully released change log lock

并且不应用任何变更集,因此很明显它会立即崩溃,因为没有设置任何表(如果我在新数据库上运行它)。我的理解是,在具有默认配置 liquibase 的 Spring Boot 应用程序中,应该在启动时运行。我认为这可能是一个依赖问题,但是为什么 liquibase 会运行呢?

任何人都可以就我可以检查什么来支持这一点提供一些指示吗?除非是特定的“春季启动运行”,否则 liquibase 是否不会在启动时运行?

谢谢

按要求添加的变更日志:

db.changelog-root.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"
                   logicalFilePath="root"
>
    <!-- NOTE: path is relative from src/main/resources -->
    <includeAll path="./db/changelog"/>
</databaseChangeLog>

changelog-2.5.0.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="2.5.0" xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
    <preConditions onFail="WARN" onFailMessage="Non postgres databases are not supported for SI, good luck!">
        <dbms type="postgresql"/>
    </preConditions>
    <changeSet author="kidd (manual)" id="tag-version-2.1.0">
        <tagDatabase tag="2.5.0"/>
    </changeSet>

    <!-- mobile_uid_seq -->
    <changeSet author="kidd (modified)" id="1635825727316-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <sequenceExists sequenceName="mobile_uid_seq"/>
            </not>
        </preConditions>
        <createSequence cacheSize="1" cycle="false" dataType="bigint" incrementBy="1" maxValue="9223372036854775807" minValue="-1" sequenceName="mobile_uid_seq" startValue="-1"/>
    </changeSet>

<!-- ... a lot more changesets --> 
</databaseChangeLog>

【问题讨论】:

  • 显示你的数据库变更日志文件
  • @SyedMehtabHassan 我已经添加了变更日志,尽管正如我所说,在 IntelliJ 中运行或使用 mvn:spring-boot run 时变更日志运行良好,所以我认为问题不在于变更日志本身。
  • @SyedMehtabHassan 实际上我收回了!作为健全性检查,我在根目录中添加了一个更改日志,并成功应用了它。所以我认为 语句中的相对路径在编译后的 jar 上不起作用,但在使用 spring boot 运行时确实起作用......仍然不确定问题出在哪里。

标签: java spring-boot maven liquibase


【解决方案1】:

问题解决了

&lt;includeAll path="./db/changelog"/&gt;&lt;includeAll path="/db/changelog"/&gt;。尽管如果有人能解释为什么运行编译的 jar (java -jar app.jar) 和 mvn:spring-boot run 会有所不同,那对我来说会很有趣。我知道文件路径在编译时会发生变化,即使查看 target 文件夹,它仍然应该是相同的相关路径(在这种情况下,db 是遵循正常 liquibase 布局的根文件夹)。所以对于为什么 ./ 在这种情况下不应该工作仍然有些困惑。

无论如何,如果有人再次遇到此问题,即使在资源文件夹中也不要使用相对路径!

【讨论】:

    猜你喜欢
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    相关资源
    最近更新 更多