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

Quarkus集成Liquibase执行SQL异常:日志显示成功但SQL未生效

问题描述

运行Quarkus + Liquibase应用时出现以下错误:

"Quarkus Main Thread", "message" : "Cannot load service: liquibase.hub.HubService: Provider liquibase.hub.core.StandardHubService could not be instantiated"

虽然控制台显示changeLog.xml执行成功,DATABASECHANGELOG表中已新增对应Changeset ID记录(EXECUTYPE为EXECUTED),但.sql文件中的INSERT语句并未实际执行。


相关配置信息

依赖配置(pom.xml)

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-liquibase</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-jdbc-mssql</artifactId>
</dependency>

应用配置(application.properties)

quarkus.liquibase.migrate-at-start=true

changeLog.xml内容

<?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
    https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
    http://www.liquibase.org/xml/ns/dbchangelog
    https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
    
<changeSet author="liquibase-test-5" id="sqlFile-example-5">
     <sqlFile dbms="sqlserver" splitStatements="true"
        path="liquibase-test.sql"
        relativeToChangelogFile="true"
        stripComments="true"/>
</changeSet>
    
</databaseChangeLog>

liquibase-test.sql内容

INSERT INTO dbo.TestTable (id,name) VALUES (2,'Salman');

解决方案

1. 处理HubService错误

这个错误是Liquibase Hub依赖缺失导致,不影响Changeset标记,但会干扰日志排查,可通过以下两种方式解决:

  • 添加Hub依赖:在pom.xml中加入
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-hub</artifactId>
    </dependency>
    
  • 禁用Liquibase Hub(推荐):在application.properties中添加
    liquibase.hub.mode=off
    

2. 排查SQL未执行的核心问题

(1)验证文件路径

确保liquibase-test.sql与changeLog.xml在同一目录(Maven项目默认Liquibase资源目录为src/main/resources/db/changeLog)。

(2)检查dbms匹配性

确认<sqlFile>标签的dbms="sqlserver"与实际连接的数据库类型一致,可通过application.properties的数据库URL验证:

quarkus.datasource.jdbc.url=jdbc:sqlserver://<host>:<port>;databaseName=<dbname>

若类型不匹配,Liquibase会跳过SQL执行但仍标记Changeset为已执行。

(3)校验SQL语句与权限

  • 直接在数据库客户端执行INSERT语句,确认表存在、字段类型匹配、SQL语法正确;
  • 检查数据库用户是否拥有INSERT权限。

(4)开启详细日志排查

在application.properties中添加日志配置,查看执行细节:

quarkus.log.category."liquibase".level=DEBUG

启动后查看日志,确认是否有SQL执行跳过、语法错误等信息。

(5)重置Changeset执行记录

若确认Changeset被错误标记为已执行,手动删除DATABASECHANGELOG表中对应id="sqlFile-example-5"、author="liquibase-test-5"的记录,重启应用重新执行。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 18:33:13