Liquibase maven:春季启动开始时找不到更改日志位置

时间:2018-07-06 06:20:51

标签: java spring maven spring-boot liquibase

我的liquibase maven插件配置为:

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>${liquibase.version}</version>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
        </dependency>
    </dependencies>
    <configuration>
        <skip>${liquibase.skip}</skip>
        <propertyFileWillOverride>true</propertyFileWillOverride>
        <changeLogFile>src/main/resources/db.changelog-master.xml</changeLogFile>
        <propertyFile>src/main/resources/${project.artifactId}-liquibase.properties</propertyFile>
        <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
    </configuration>
</plugin>

启动spring-boot时出现以下错误消息:

  

org.springframework.beans.factory.BeanCreationException:创建名称为'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration $ LiquibaseConfiguration'的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalStateException:找不到更改日志位置:类路径资源[db / changelog / db.changelog-master.yaml](请添加更改日志或检查您的Liquibase配置)

我不太清楚为什么liquibase设置后为什么要尝试选择此变更日志文件db/changelog/db.changelog-master.yaml

<changeLogFile>src/main/resources/db.changelog-master.xml</changeLogFile>

我的变更日志:

<?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                     
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">

    <changeSet author="ddd" id="tdev-forum-service-1"
        context="dev, int, rel" labels="tdev-forum-service">
        <createTable tableName="TDEV_FORUM" remarks="Discussions about shared code">
            <column name="FORUM_ID" type="VARCHAR(36)">
                <constraints nullable="false" primaryKey="true" />
            </column>

            <column name="TOPIC_NAME" type="VARCHAR(128)">
                <constraints nullable="false" />
            </column>

            <column name="TOPIC_CATEGORY" type="VARCHAR(32)">
                <constraints nullable="false" />
            </column>

            <column name="SOURCE_CODE_ITEM_ID" type="VARCHAR(36)">
                <constraints nullable="false" />
            </column>

        </createTable>

    </changeSet>



    <changeSet author="ddd" id="tdev-forum-service-2"
        context="dev" labels="tdev-forum-service">

        <insert tableName="TDEV_FORUM">
            <column name="FORUM_ID" value="36afbfcd-969d-4a0e-9d63-25bd9d4e8f6b" />
            <column name="TOPIC_NAME" value="How to read a text file using streams" />
            <column name="TOPIC_CATEGORY" value="I/O Streams" />
            <column name="SOURCE_CODE_ITEM_ID" value="4600eab2-c375-4b99-97ab-9670ed93f861" />
        </insert>

        <rollback>
            <delete tableName="TDEV_FORUM">
                <where>FORUM_ID='36afbfcd-969d-4a0e-9d63-25bd9d4e8f6b'</where>
            </delete>
        </rollback>
    </changeSet>



    <changeSet author="ddd" id="tdev-forum-service-3"
        context="dev, int, rel" labels="tdev-forum-service">
        <createTable tableName="TDEV_FORUM_MESSAGE" remarks="Messages from developers">
            <column name="MESSAGE_ID" type="VARCHAR(36)">
                <constraints nullable="false" primaryKey="true" />
            </column>

            <column name="FORUM_ID" type="VARCHAR(36)">
                <constraints nullable="false" />
            </column>

            <column name="CONTENT" type="TEXT">
                <constraints nullable="true" />
            </column>

        </createTable>

    </changeSet>

    <changeSet author="sdd" id="tdev-forum-service-4"
        context="dev, int, rel" labels="tdev-forum-service">

        <addForeignKeyConstraint baseColumnNames="FORUM_ID"
            baseTableName="TDEV_FORUM_MESSAGE" constraintName="FK_MESSAGE_FORUM"
            deferrable="true" initiallyDeferred="true" onDelete="CASCADE"
            onUpdate="RESTRICT" referencedColumnNames="FORUM_ID"
            referencedTableName="TDEV_FORUM" />
    </changeSet>

</databaseChangeLog>

1 个答案:

答案 0 :(得分:7)

默认情况下,Spring Boot期望您使用yaml格式的变更集文件而不是xml。 而且位置db/changelog/db.changelog-master.yaml似乎也是default value

因此,您可能无法覆盖这些默认设置。

这里是documentation,介绍如何在Spring Boot中覆盖此内容。

据我所知(我不使用Spring Boot),您需要在spring.liquibase.change-log中设置属性application.properties