Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 弹簧靴2不适用于Postgres_Java_Spring_Spring Boot_Jpa - Fatal编程技术网

Java 弹簧靴2不适用于Postgres

Java 弹簧靴2不适用于Postgres,java,spring,spring-boot,jpa,Java,Spring,Spring Boot,Jpa,我有一个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 drive

我有一个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>

如何解决此问题?

您刚刚更改了依赖项,如下所示。在依赖项中包含版本和范围元素

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

postgresql
postgresql
9.1-901.jdbc4
运行时

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

共享堆栈跟踪它将消失helpful@GauravSrivastavdonetry在datasource内部使用属性:
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
看看这篇文章:它仍然是相同的问题它仍然是相同的问题你的postgres版本是什么,jar应该与它兼容。还有一件事需要检查是否下载了依赖项。
<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901.jdbc4</version>
    <scope>runtime</scope>
</dependency>