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

Spring Boot+Maven配置Liquibase执行diff命令遇驱动找不到错误

解决Liquibase diff时找不到HibernateDriver的问题

咱先把问题根源说透:你遇到的Cannot find database driver: liquibase.ext.hibernate.database.connection.HibernateDriver错误,核心是依赖版本冲突+必要依赖缺失——你的Liquibase插件里配了过低版本的Spring依赖,和Spring Boot 2.3.1自带的高版本Spring组件打架,同时Hibernate相关的核心依赖也没给足。

具体修复步骤

1. 删掉插件里的冲突Spring依赖

你在liquibase-maven-plugin的依赖里加了spring-beans:4.1.7.RELEASE和spring-data-jpa:1.7.3.RELEASE,这俩版本比Spring Boot 2.3.1自带的Spring 5.2.6低太多,直接删掉就行!Spring Boot的parent已经帮你管理了所有Spring组件的正确版本,不需要手动引入旧版本拖后腿。

2. 补全Liquibase Hibernate扩展的依赖

你用的Liquibase核心版本是3.10.2,对应的liquibase-hibernate5版本匹配是对的,但得给插件补上Hibernate核心依赖,确保驱动类能被正常加载。

3. 修正后的Liquibase Maven插件配置

把插件部分改成下面这样:

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>3.10.2</version>
    <configuration>
        <propertyFileWillOverride>true</propertyFileWillOverride>
        <propertyFile>src/main/resources/liquibase.properties</propertyFile>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.liquibase.ext</groupId>
            <artifactId>liquibase-hibernate5</artifactId>
            <version>3.10.2</version>
        </dependency>
        <!-- 补上Spring Boot 2.3.1对应的Hibernate核心依赖 -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.17.Final</version>
        </dependency>
        <!-- 保留Spring Boot JPA依赖,确保Spring侧的Hibernate配置能被识别 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>
        <!-- 可选:如果还是报错,加上PostgreSQL驱动依赖 -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.14</version>
        </dependency>
    </dependencies>
</plugin>

4. 检查liquibase.properties的实体路径

确保referenceUrl里的实体包路径是你项目的真实路径,别写错:

referenceUrl=hibernate:spring:com.something.something.models?dialect=org.hibernate.dialect.PostgreSQLDialect

这里的com.something.something.models要替换成你实际存放实体类的包名。

5. 执行前的准备

先跑一遍mvn clean compile,确保所有依赖都正确下载并编译到位,之后再执行mvn liquibase:diff应该就能正常运行了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 20:22:57