52

I am getting following error when I try to run spring boot application.

Description:

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

    Property: driverclassname
    Value: oracle.jdbc.OracleDriver
    Origin: "driverClassName" from property source "source"
    Reason: Unable to set value for property driver-class-name

Action:

Update your application's configuration

This is same issue I have but i am not using maven.

I am using spring Boot 2.0.0 with following starters.

dependencies {
    compile "org.springframework.boot:spring-boot-starter-web"
    compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
    testCompile "org.springframework.boot:spring-boot-starter-test"
}

And this is my application.properties file

spring.datasource.url= *****
spring.datasource.username= ******
spring.datasource.password= ******
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user9735824
  • 1,196
  • 5
  • 19
  • 36

16 Answers16

42

Same problem with me (Spring boot 2),

I Fixed add driver-class.

Look up application.properties file.

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

Full code.

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=upate
spring.datasource.url=jdbc:mysql://localhost:3306/database_name
spring.datasource.username=admin
spring.datasource.password=admin1234
bamossza
  • 3,676
  • 1
  • 29
  • 28
34

As Stephane Nicoll said, you don't have driver on your classpath. You need to include jdbc driver on your gradle build as below. However, you don't have to stick to driver version that I have included.

dependencies {
    compile "org.springframework.boot:spring-boot-starter-web"
    compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1"
    testCompile "org.springframework.boot:spring-boot-starter-test"
    runtime('com.oracle:ojdbc7:12.1.0.2.0') 
}
want2learn
  • 2,471
  • 2
  • 20
  • 37
  • 2
    Since you've verified this question, I can only assume that was your problem. Since you haven't created an issue as I've asked in my answer, I've [created one myself](https://github.com/spring-projects/spring-boot/issues/13122) – Stephane Nicoll May 09 '18 at 15:13
  • 2
    Thanks so much for pointing this out. Had the same issue with maven - single JUnit tests did not run but the maven build did. The solution was to add the compile scope to the database connector (in memory db in my case). – CrimsonMike Oct 28 '20 at 20:54
10

I had the same error when updating from Spring Boot 2.0.6 to Spring Boot 2.1.6.

Explicitly setting driver class name spring.datasource.driver-class-name=com.mysql.jdbc.Driver in application.properties has resolved the issue

Dzmitry Bahdanovich
  • 1,735
  • 2
  • 17
  • 34
  • From Spring Boot 2.1.0 the default driver name for mysql connections is com.mysql.cj.jdbc.Driver: https://github.com/spring-projects/spring-boot/issues/13688. commit: 18904ec29138080dcfc707b6150dc0069b7a0ac4. If it's possible to update the mysql connector with with one compatible (driverName= com.mysql.cj.jdbc.Driver), that would be a good option. If not, this one is good workaround – chindo Sep 15 '20 at 15:21
9

I have added the below in properties file

spring.datasource.driverclassname = com.mysql.jdbc.Driver hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

and added the below in POM file

        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>

It is working fine now.

Bibin Zacharias
  • 159
  • 1
  • 2
  • 7
  • I am using oracle and gradle. So this answer is not correct. – user9735824 Aug 16 '18 at 13:45
  • @Bibin Worked for me as i was using mySQL, But now i am getting another exception: __com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.__ – Aakash Patel Jan 31 '19 at 17:00
6

You have to add

   <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency> 

dependency in your pom.xml file

Miraj Hamid
  • 554
  • 10
  • 19
4

The driver is not on your classpath, this is an interesting problem and I think the failure analyzer can be improved to avoid that misleading message. If that's your problem, please confirm and open an issue so that we try to improve it.

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
3

We have to add the dependency and have to remove property "spring.datasource.driver-class-name"

 <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency> 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Naveen Yalla
  • 141
  • 1
  • 11
2

In case anyone is running intelliJ this error isn't immediately clear it can be caused by a missing profile. Eg. missing vm args for -Dspring.profiles.active=local (or whatever your property file name might be)

Rebecca Douglas
  • 429
  • 1
  • 5
  • 16
  • I am still facing this issue, though when running my app it will use the default profile. So it shouldn't matter right? No solution seems to work though. – J-me Nov 17 '19 at 19:40
  • Did you check what profile you're running in the run configurations? – Rebecca Douglas Nov 19 '19 at 15:10
  • I don't have any profile set, so when i the app it Will say: no profile found, switched to profile default. Profiles are things a developer Just maken op right, so I was wondering why it would even matter. – J-me Nov 20 '19 at 08:16
2

You just need to add below in pom.xml

     <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
biddut
  • 353
  • 3
  • 6
2

If youre running intelliJ and run into this issue just add this dependency in your pom.xml file:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>
Karmic Coder
  • 17,569
  • 6
  • 32
  • 42
Sam K.
  • 31
  • 3
2

This happened to me as well. But after adding the correct MySQL version in my pom.xml, and explicitly adding the driver details to application.properties resolved the issue.

  1. Application.properties

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

  2. pom.xml

     <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.34</version>
     </dependency>
    

Add the MySQL version to pom.xml as per the version installed.

rahul soni
  • 23
  • 8
0

Check your pom.xml if you dont have the mysql dependency, can add like this

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
</dependency>

Befor of update the file, run maven

mvn clean install

to update your maven's dependencies

0

I had the same error, the mistake was in pom.xml file. I had a mistake in my SQL connector dependency. If its okay in your case check also application.properties file you may not include driver

spring.datasource.url=jdbc:mysql://localhost:3307/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

spring.mvc.view.prefix = /WEB-INF/jsp/
spring.mvc.view.suffix = .jsp
0

All of these answers require code changes, and in my situation the code wasn't the problem. The error would occur randomly in my development environment, seamingly for no reason, not associated with any config or code change that I'd made.

I think I've found a consistent way to fix it, but I'm not sure why it works.

  1. Shut down InteliJ IDEA
  2. Delete ".idea" and "build" folders
  3. Restart IDEA

This seems to resolve it, but the random nature of this really bothers me. I don't know why it occurs, or why the above fixes it.

I'm just adding this in case it helps others.

user1751825
  • 4,029
  • 1
  • 28
  • 58
0

I only needed to re-import all gradle dependencies.

Odys
  • 8,951
  • 10
  • 69
  • 111
0

Add the maven dependency

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

Add or modify the application.properties file.

    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

Older version used:

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

This does NOT work anymore; hence, the change to spring.jpa.properties.hibernate.dialect.

Resulting in the following:

spring.datasource.url=jdbc:mysql://localhost:3306/<db name>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=<db username>
spring.datasource.password=<db password>

spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.database=mysql
spring.jpa.show-sql=true

Clean the build artifacts from previous builds

mvn clean install

An for IntelliJ, invalidate the cache and restart.
File --> Invalidate Caches...

Run the project.

Edward Ames
  • 129
  • 4