【问题标题】:"Cannot find database driver: Driver class was not specified and could not be determined from the url" error on using liquibase-hibernate plugin“找不到数据库驱动程序:未指定驱动程序类,无法从 url 确定”使用 liquibase-hibernate 插件时出错
【发布时间】:2020-06-03 04:26:14
【问题描述】:

我正在尝试在数据库和持久性实体之间从 diffs 生成 changeLog

我正在使用 liquibase hibernate 插件

<plugins>
    <plugin>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>3.4.1</version>
        <configuration>                  
            <propertyFile>src/main/resources/liquibase.properties</propertyFile>
        </configuration> 
        <dependencies>
            <dependency>
                <groupId>org.liquibase.ext</groupId>
                <artifactId>liquibase-hibernate4</artifactId>
                <version>3.5</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>4.1.7.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-jpa</artifactId>
                <version>1.7.3.RELEASE</version>
            </dependency>
        </dependencies>               
    </plugin> 
</plugins> 

我的liquibase.properties 是这样的

changeLogFile=classpath:liquibase-changeLog.xml
url=jdbc:postgres://localhost:5432/oauth_reddit
username=tutorialuser
password=tutorialmy5ql
driver=org.postgresql.Driver
referenceUrl=com.sample.App
  ?dialect=org.hibernate.dialect.PostgreSQLDialect
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml

在执行mvn liquibase:diff 时,我收到以下错误

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:diff (default-cli) on project prototype-liquibase-migration: Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (com.sample.App?dialect=org.hibernate.dialect.PostgreSQLDialect) -> [Help 1]

我已经在liquibase 属性中指定了Driver,但它似乎没有使用。我做错了什么?

【问题讨论】:

    标签: liquibase liquibase-hibernate


    【解决方案1】:

    问题出在liquibase.properties中的referenceUrl,referenceUrl正在使用包扫描,所以url必须以hibernate:spring:开头。

    我变了

    referenceUrl=com.sample.App?=org.hibernate.dialect.PostgreSQLDialect
    

    进入

    referenceUrl=hibernate:spring:com.sample.App?dialect=org.hibernate.dialect.PostgreSQLDialect
    

    这解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多