Home > Software design >  Failed to determine a suitable driver class in CMD
Failed to determine a suitable driver class in CMD

Time:06-29

Im developing spring boot Rest API, application, In my VS code application is running without any runtime errors and working with postman too, VS code runtime output enter image description here however, when i export the JAR file via VS code, and try to run cmd, that file pop up run time error, ERROR

Blockquote enter image description here

Blockquote Error Msg in cmd

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

My POM XML

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>

application.properties

## Server Properties
server.port= 8083
server.servlet.context-path= /TEST-API

spring.datasource.url= jdbc:mysql://localhost:3306/TEST?useSSL=false&useLegacyDatetimeCode=false&zerodatetimebehavior=Converttonull
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username= root
spring.datasource.password= 1234
spring.datasource.testWhileIdle = true
spring.datasource.timeBetweenEvictionRunsMillis = 60000
spring.datasource.validationQuery = SELECT 1 

Could you please help me on this?

CodePudding user response:

Option 1

Try use

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

instead of

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

in your properties file, if you are using mysql version < 8

Option 2

Check if your driver of mysql (JAR file) was included in the library of WAR --> WEB-INF/lib.

Option 3

If you are not fix it yet, and you have other database in your machine like a postgres:

  • change this connection to this another database.
  • test inside of your editor/ide
  • export to war
  • if the problem happens the same way, you can be right that your export process is the problem. So try use the plugin of maven to generate the war: https://maven.apache.org/plugins/maven-war-plugin/usage.html

CodePudding user response:

Thanks for your support one of my friends help me to fix the issue what they did is, delete mvnw file from the project path. Then paste apache-maven-3.6.0 in to C driver and then did the maven install and package the project in vs code. After that project jar generated.

  • Related