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

多模块Spring Boot集成H2与Liquibase找不到子变更日志文件求助

问题原因
  • master.xml的<include>标签默认从classpath根路径查找子变更文件,未配置相对路径属性时,无法匹配到与master.xml同目录下的v-1-0-0、v-1-0-1子目录中的文件
  • 多模块场景下,若启动模块未正确引入dao模块依赖,或dao模块的resources目录下的db文件夹被maven过滤规则排除,会导致变更文件未被打包进运行时classpath
  • 同时配置application.properties和独立liquibase.properties,两套数据源、变更日志路径配置存在冲突,干扰Liquibase的资源加载逻辑,Spring Boot环境下无需单独配置liquibase.properties
解决方案
  1. 修正master.xml的include标签,添加relativeToChangelogFile="true"属性,指定子文件相对于master.xml路径查找,修改后内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<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
        https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <include file="v-1-0-0/changelog-project-v-1.0.0-cumulative.xml" relativeToChangelogFile="true"/>
    <include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml" relativeToChangelogFile="true"/>
    
</databaseChangeLog>
  1. 调整application.properties配置,将变更日志路径的前缀改为classpath*:,支持扫描所有依赖模块下的对应路径:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=password
spring.liquibase.change-log=classpath*:db/migration/master.xml
  1. 清理冗余配置:删除dao模块下的liquibase.properties文件,避免和Spring Boot自动配置冲突。

  2. 检查多模块依赖:确认存放启动类的模块pom.xml中已引入dao模块依赖,同时检查dao模块的maven配置,确认没有配置过滤规则排除db/目录下的xml文件,编译后dao模块的target/classes目录下存在db/migration/完整目录结构。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.15 12:15:03