liquibase 不 运行 与 java -jar SpringBoot

liquibase does not run with java -jar SpringBoot

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

当我编译成一个 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

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

任何人都可以就我可以检查的内容提供一些建议来支持这一点吗? liquibase 是否在启动时不 运行 除非它是特定的“spring 引导 运行”?

谢谢

根据请求添加的变更日志:

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>

问题已通过更改解决

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

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