【问题标题】:Driver org.h2.Driver claims to not accept jdbcUrl [closed]驱动程序 org.h2.Driver 声称不接受 jdbcUrl [关闭]
【发布时间】:2021-09-19 07:14:37
【问题描述】:

我开始使用 springboot 并提出了这个我无法解决的错误。

java.lang.RuntimeException: Driver org.h2.Driver 声称不接受 jdbcUrl, jdbc:postgresql://localhost:5432/testdb

我的 pom.xml 依赖项

<properties>
        <java.version>16</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.200</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

我的应用程序.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/testdb
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true
spring.datasource.driverClassName=org.h2.Driver

【问题讨论】:

  • 您正在使用 h2 JDBC 驱动程序,org.h2.Driver 和 Postgres JDBC URL。

标签: java spring postgresql spring-boot hibernate


【解决方案1】:

您错误地引用了内存数据库中的 h2,请将驱动程序类名称更改为

spring.datasource.driver-class-name=org.postgresql.Driver

【讨论】:

    猜你喜欢
    • 2020-10-29
    • 2021-10-19
    • 2019-09-26
    • 2020-08-05
    • 2020-11-02
    • 2019-08-17
    • 2020-06-06
    • 2011-11-11
    • 1970-01-01
    相关资源
    最近更新 更多