Liquibase 4.0 中删除了通过绝对路径指定文件

问题描述 投票:0回答:7

当我运行 Spring Boot 应用程序时,出现以下 liquibase 错误:

在 Liquibase 4.0 中删除了通过绝对路径指定文件的功能。请使用相对路径或在类路径参数中添加“/”。

这是application.yaml中的类路径:

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

我也尝试过:

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

这是文件夹结构:

Changlog大师:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

    <include file="db-changelog-1.0.xml"/>
</databaseChangeLog>
spring-boot liquibase changelog
7个回答
4
投票

我将变更日志文件放在资源文件夹之外时遇到了这个问题,但是如果我将它们包含在resources/db/changelog下,那么设置以下配置就可以正常工作。

spring.liquibase.change-log=classpath:/db/changelog/changelog-master.xml

在 4.6.2 下测试


3
投票

不幸的是,这仍然是一个悬而未决的问题。请参阅2281


2
投票

看起来这个问题已在 v4.4.3 中修复了


1
投票

只需尝试从“change-log:”参数中删除“classpath:”。 另请尝试检查您的 pom.xml (配置中的“changeLogFile”标记): 更改日志文件路径之前不应有“${basedir}”。

<changeLogFile>
  /src/main/resources/liquibase/changelog.xml
</changeLogFile>

1
投票

此处解释

Liquibase 类路径在 4.0 版本之前如何工作

4.0版本之前,Liquibase添加的默认位置之一 类路径是文件系统中的根目录 (/)。这 由于依赖于机器的变更日志路径,变更导致了问题, 例如 /home/my-user/projects/liquibase/changelog.xml,位于 / 目录。这样,Liquibase 使用给定路径作为 存储在 DATABASECHANGELOG 表中的变更集标识符,以及 当您运行 Liquibase 时 /home/other-user/projects/liquibase/changelog.xml,Liquibase 看到它 作为不同的变更日志并尝试重新运行所有以前运行的 变更集。

为了防止发生识别问题,删除了 / 作为 类路径的默认部分。 Liquibase 类路径如何工作 4.0及以上版本

从 Liquibase 4.0 开始,根目录(/)不再是 由于中提到的问题,类路径的默认部分 上一节。

...

消息“请使用相对路径或在类路径参数中添加‘/’。”指的是根目录“/”,并不意味着在类路径路径的开头添加斜杠。 Afaik,

classpath:x
classpath:/x
是一样的。

此外,无论出于何种原因,当找不到主变更日志时,都会出现该消息,因此拼写错误也可能导致此消息。这只是一个提示,告诉您可能找不到它,因为该文件不在类路径上,因为他们从类路径中删除了根目录,但也找不到它,因为您指定了错误的路径(我刚刚这样做了) .

要正确配置它,主变更日志必须位于 Liquibase 类路径上。在 Spring Boot 中,Liquibase 类路径设置为应用程序的类路径,即您可以使用

src/main/resources

Tl;dr:当您的文件

src/main/resources/db/changelog/db.changelog-master.xml
使用时
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml

我不知道某些 Liquibase 版本是否存在错误,但无论如何,这就是“应该”工作的方式。


0
投票

下面的代码对我有用

<build> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.sql</include> </includes> </resource> </resources> </build>



0
投票
IntelliJ

下遇到了这个问题,具有 spring-boot 2.7.9 依赖性。

但奇怪的是,在命令行上直接使用 
Maven
运行这些测试时却没有。 无论如何,我将 spring-boot 依赖项更改为

spring-boot 2.7.14

,它解决了我的问题。

    

© www.soinside.com 2019 - 2024. All rights reserved.