4

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:

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?

N. Labrahmi
  • 657
  • 4
  • 23
Aymen Kanzari
  • 1,765
  • 7
  • 41
  • 73

2 Answers2

0

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>
Gaurav Srivastav
  • 2,381
  • 1
  • 15
  • 18
0

I had this problem when using spring profiles in my application.yml. I only defined the spring.datasource.* properties in the profile's section of the yaml. However, when I moved those properties to the MAIN section (i.e. the default profile), the problem disappeared.