You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3升级后Liquibase找不到changelog目录报错求助

Spring Boot 3升级后Liquibase sqlFile路径丢失"changelog"的问题解决

问题现象

升级Spring Boot 3后,Liquibase执行时抛出文件找不到错误:

liquibase.exception.UnexpectedLiquibaseException: java.io.FileNotFoundException: JAR entry db/scripts/dml/importstatus.sql not found

实际文件路径应为db/changelog/scripts/dml/importstatus.sql,但路径中的changelog部分被莫名忽略。仅使用property变量或直接指定相对路径的sqlFile标签出现该问题,其他changeSet可正常运行。

相关配置代码:

<property name="script-dir" value="scripts/dml" dbms="postgresql"/>

<changeSet id="insert-import-status">
    <sqlFile path="${script-dir}/importstatus.sql"
             splitStatements="false"
             stripComments="false"
             encoding="utf8"
             relativeToChangelogFile="true"
             endDelimiter=";"/>
</changeSet>

尝试直接替换为path="scripts/dml/importstatus.sql",错误依旧。

可能原因

Spring Boot 3升级后,配套的Liquibase版本(通常为4.19+)对relativeToChangelogFile的路径解析逻辑或类路径资源加载方式进行了调整,导致相对路径的基准目录计算错误,丢失了changelog层级。

解决方案

1. 使用绝对类路径指定文件

直接通过classpath:前缀指定完整路径,绕过相对路径解析问题:

<changeSet id="insert-import-status">
    <sqlFile path="classpath:db/changelog/scripts/dml/importstatus.sql"
             splitStatements="false"
             stripComments="false"
             encoding="utf8"
             endDelimiter=";"/>
</changeSet>

如果要保留property变量,调整变量值为完整类路径:

<property name="script-dir" value="classpath:db/changelog/scripts/dml" dbms="postgresql"/>

<changeSet id="insert-import-status">
    <sqlFile path="${script-dir}/importstatus.sql"
             splitStatements="false"
             stripComments="false"
             encoding="utf8"
             endDelimiter=";"/>
</changeSet>

2. 确认主changelog文件位置

确保项目的主changelog文件(如db.changelog-master.xml)确实位于db/changelog目录下。relativeToChangelogFile="true"的基准路径是主changelog文件所在的目录,若主文件位置变更,相对路径的基准也会随之改变。

3. 显式配置Liquibase变更日志路径

在application.properties或application.yml中明确指定Liquibase的主变更日志路径,确保路径基准正确:

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

4. 临时降级Liquibase版本(不推荐长期使用)

若上述方法均无效,可临时降级Liquibase到Spring Boot 2.x兼容的版本(如4.18.x),但建议尽快适配新版本逻辑,避免依赖旧版本带来的风险。

内容的提问来源于stack exchange,提问作者user20965775

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:05:31