簡體   English   中英

Spring Boot 2不適用於Postgres

[英]Spring boot 2 does not work with Postgres

我有一個Spring Boot JPA應用程序,帶有spring boot 2.0.3.RELEASE並連接到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

我怎么解決這個問題?

您剛剛更改了依賴項,如下所示。 在依賴項中包含版本和范圍元素。

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

我在application.yml中使用spring profile時遇到了這個問題。 我只在yaml的配置文件部分中定義了spring.datasource。*屬性。 但是,當我將這些屬性移動到MAIN部分(即默認配置文件)時,問題就消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM