java - 驱动程序 org.h2.Driver 声称不接受 jdbcUrl

标签 java spring postgresql spring-boot hibernate

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

java.lang.RuntimeException: Driver org.h2.Driver claims to not accept 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>

我的应用程序属性

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,请将驱动程序类名称更改为

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

关于java - 驱动程序 org.h2.Driver 声称不接受 jdbcUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69241112/

相关文章:

java - 安卓图标电池

java - 创建返回带有指定消息的 JOptionPane.showMessageDialog 的方法?

Spring 启动 : read list from yaml using @Value or @ConfigurationProperties

postgresql - 在 postgresql 中跟踪修订

database - sequelize 在特定条件下更改数据

java - 在 android 中从 byte[] 写入文件失败

java - FacesContext.getCurrentInstance().getApplication().getMessageBundle() 返回哪个 messageBundle?

java - Spring @Autowired 字段为空。我在不同的类中使用@AutoWired Fields

java - 升级后 Eclipse "Unable to instantiate class JavaSourceLookupDirector, Expecting stackmap frame at branch target 53"

sql - 使用 PostgreSQL 选择一棵树并对 child 进行排序