spring - 使用 H2 和 Spring 引导进行 Liquibase 迁移
问题描述
我使用 Spring Boot 和 H2 DB。我想在我的应用程序中包含 Liquibase。我有多个模块应用程序。有entity、dao、service、controller等模块。我在 Dao 模块中创建了 Liquibase 文件。这是 application.property:
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
这是 liquibase.property:
classpath=
changeLogFile=db/migration/master.xml
url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
username=sa
password=password
driver=org.h2.Driver
这是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"/>
<include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml"/>
</databaseChangeLog>
我有一个错误:
Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: The file v-1-0-0/changelog-project-v-1.0.0-cumulative.xml was not found in
- Spring resources
但是,我认为我不需要在属性中指定来自 master.xml 的文件。请帮忙。 在此处输入图像描述
解决方案
看起来路径changelog-project-v-1.0.0-cumulative.xml
不正确。尝试使用relativeToChangelogFile="true"
输入master.xml
以下内容:
<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>
推荐阅读
- node.js - 我希望我的服务器是唯一可以访问我的 API 的服务器,我可以使用秘密来确保这一点吗?
- arrays - 无法将一个数组中记录的属性分配给另一个数组中的记录
- java - 检查字符串的字符是否可以重新排列以形成回文
- ruby-on-rails - Rails 6 页面寻找 application.js 的预编译版本
- react-native - 有没有办法可以在使用 React Native 的其他组件上使用 headerRight 的 onpress 功能
- python - 实时物体检测
- python - 如何获得 2 个不同列表的余弦相似度?
- javascript - 如何在 React js 的输入框中禁用复制粘贴
- java - 将子类型添加到通用列表
- api - Flutter:快照未显示数据