小编Uta*_*dru的帖子

带有 spring-boot 的自定义 sql 中的 Liquibase 参数

我在 jdk 11 上有一个 spring-boot 应用程序,使用 maven,具有以下 liquibase 依赖项:

   <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>3.6.2</version>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

更改日志主文件名为 db.changelog.xml ,位于 PROIECTTEST\src\main\resources\db 下,在 application.properties 上具有以下配置:

spring.liquibase.change-log=classpath:/db/db.changelog.xml
spring.liquibase.default-schema=public
liquibase.parameters.schema=public
Run Code Online (Sandbox Code Playgroud)

看起来像:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">

    <include relativeToChangelogFile="true" file="changelog/initial/test.xml"/>     
</databaseChangeLog>
Run Code Online (Sandbox Code Playgroud)

我的变更集 test.xml 文件位于 PROIECTTEST\src\main\resources\db\changelog\initial 看起来像:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
    <changeSet author="test" id="1540963204914-19">
    <sql > 
    select * from ${schema}.test
    </sql>

    </changeSet>

</databaseChangeLog>
Run Code Online (Sandbox Code Playgroud)

当我使用命令 mvn spring-boot:run 启动 spring-boot 服务器时,liquibase sql 失败并出现以下错误:“$”处或附近的语法错误。

我错过了什么吗?从我读到的 application.properties …

liquibase maven spring-boot

4
推荐指数
1
解决办法
3690
查看次数

标签 统计

liquibase ×1

maven ×1

spring-boot ×1