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

SpringBoot启动报错:Liquibase找不到classpath下的changelog文件

Liquibase changelog路径不存在报错排查方案

1. 资源目录配置问题

Maven默认仅将src/main/resources下的文件打包到类路径中,如果你的changelog文件未放在该目录,或未配置额外资源扫描规则,就会触发该报错。

  • 解决方法1:确认db/changelog/dbchangelog.xml完整路径在src/main/resources目录下,层级和配置完全匹配
  • 解决方法2:如果文件放在其他自定义目录,在pom.xml的<build>标签下添加资源扫描配置:
<resources>
    <resource>
        <directory>src/main/你的自定义目录</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>
    <!-- 保留默认resources目录的扫描 -->
    <resource>
        <directory>src/main/resources</directory>
    </resource>
</resources>

2. 大小写匹配问题

类路径资源加载严格区分大小写,Windows系统本地调试不区分大小写容易忽略该问题,部署到Linux/macOS环境就会报错。

  • 解决方法:检查changelog文件名、目录名的大小写,确保和配置db/changelog/dbchangelog.xml完全一致,比如不要出现DbChangelog.xml、dbchangelog.XML这类写法。

3. 编译同步问题

开发工具经常会出现新增资源文件未同步到编译输出目录的情况,导致运行时找不到。

  • 解决方法:执行mvn clean compile命令重新编译整个项目,再启动应用。如果使用IDEA开发,可以右键项目点击Reload All Maven Projects后再重启。

4. 配置格式问题

yaml配置对缩进和空格非常敏感,有可能配置路径存在不可见的多余空格。

  • 解决方法:检查spring.liquibase.change-log的配置值,确认classpath:db/changelog/dbchangelog.xml前后没有多余空格,缩进层级正确。

快速验证方法

可以在项目启动类的main方法中添加以下代码,直接验证类路径下是否存在目标文件,快速定位问题:

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import java.io.IOException;

public class DemoApplication {
    public static void main(String[] args) {
        // 新增验证代码
        try {
            Resource resource = new ClassPathResource("db/changelog/dbchangelog.xml");
            System.out.println("changelog文件是否存在:" + resource.exists());
            if (resource.exists()) {
                System.out.println("changelog实际路径:" + resource.getURL());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 原有启动代码
        SpringApplication.run(DemoApplication.class, args);
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 20:06:03