Spring Boot 2 不兼容 Postgres。

4

我有一个使用Spring Boot 2.0.3.RELEASE开发的JPA应用程序,连接到PostgreSQL数据库,但在运行应用程序时,我遇到了以下错误信息:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class

数据库连接属性:

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/testS
    username: postgres
    password: postgres123
    driver-class-name: org.postgresql.Driver

依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
    </dependency>

堆栈跟踪:

Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

我该如何解决这个问题?

分享堆栈跟踪信息会很有帮助。 - Gaurav Srivastav
@GauravSrivastav 完成 - Aymen Kanzari
尝试在数据源中使用属性:dataSourceClassName=org.postgresql.ds.PGSimpleDataSource - user7294900
请查看此帖子:https://dev59.com/b1wX5IYBdhLWcg3w2SZq#33324144 - Thiru
它仍然是同样的问题。 - Aymen Kanzari
错误信息 Failed to configure a DataSource: 'url' attribute is not specified 表示您的 application.yml 文件根本没有被读取。 - Markus Pscheidt
2个回答

0

您刚刚更改了以下依赖项。请在依赖项中包含版本和范围元素。

<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901.jdbc4</version>
    <scope>runtime</scope>
</dependency>

它仍然是同样的问题。 - Aymen Kanzari
你的PostgreSQL版本是什么?JAR文件应该与其兼容。还有一件事要检查,就是依赖项是否已经下载。 - Gaurav Srivastav

0
我在使用应用程序.yml中的Spring配置文件时遇到了问题。 我只在yaml文件的配置文件部分中定义了spring.datasource.*属性。 但是,当我将这些属性移动到主要部分(即默认配置文件)时,问题就消失了。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接