JavaSpringBoot2不适用于Postgres
我有一个SpringBoot2.0.3的SpringBootJPA应用程序。释放并连接到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
我怎样才能解决这个问题
# 1 楼答案
您刚刚更改了依赖项,如下所示。在依赖项中包含版本和范围元素
# 2 楼答案
我在应用程序中使用spring配置文件时遇到了这个问题。yml。 我只定义了春天。数据源。*yaml的配置文件部分中的属性。 然而,当我将这些属性移动到主部分(即默认配置文件)时,问题消失了