vishesh
vishesh

Reputation: 11

Reason: Failed to determine a suitable driver class : spring boot using eclipse

I am getting following error in console :

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2020-10-09 19:17:13.032  INFO 2692 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-10-09 19:17:13.065  INFO 2692 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-09 19:17:13.073 ERROR 2692 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

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


Action:

Consider the following:
    If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
    If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

pom.xml :

?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.10.RELEASE</version>
        <relativePath />
        <!-- lookup parent from repository -->
    </parent>
    <groupId>com.merchant</groupId>
    <artifactId>merchantconfiguration</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>merchantconfiguration</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

application.properties :

spring.datasource.url=jdbc:postgresql://localhost:5432/hitachipyg_db 
spring.datasource.username=postgres
spring.datasource.password=hitachi@123
spring.jpa.show.sql=true
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto= update spring.datasource.driver-class-name=org.postgresql.Driver

Upvotes: 1

Views: 13747

Answers (2)

Jack Thomas
Jack Thomas

Reputation: 44

In my case, I had a weird directory structure, and my 'resources' directory wasn't recognized by my IDE as a resources directory. So my 'application.properties' file wasn't being used.

So make sure that your IDE is looking in the right place for resources. Make sure your file exists at 'src/main/resources/application.properties'.

Upvotes: 0

Sujay Mohan
Sujay Mohan

Reputation: 952

Could you please try the below property in you application.properties file.

spring.datasource.driver-class-name=org.postgresql.Driver

Upvotes: 5

Related Questions