[英]Spring boot 2 does not work with Postgres
I have a Spring Boot JPA application with spring boot 2.0.3.RELEASE and connects to PostgreSQL, when i run the application i get the error message below: 我有一个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
Database connection properties: 数据库连接属性:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/testS
username: postgres
password: postgres123
driver-class-name: org.postgresql.Driver
Dependencies: 依赖关系:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
Stacktrace: 堆栈跟踪:
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
How can I solve this problem? 我怎么解决这个问题?
You just changed the dependency as below. 您刚刚更改了依赖项,如下所示。 Include version and scope element in dependency. 在依赖项中包含版本和范围元素。
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
<scope>runtime</scope>
</dependency>
I had this problem when using spring profiles in my application.yml. 我在application.yml中使用spring profile时遇到了这个问题。 I only defined the spring.datasource.* properties in the profile's section of the yaml. 我只在yaml的配置文件部分中定义了spring.datasource。*属性。 However, when I moved those properties to the MAIN section (ie the default profile), the problem disappeared. 但是,当我将这些属性移动到MAIN部分(即默认配置文件)时,问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.