Skip to content

How to resolve 'Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource' in SpringBoot apps

Problem

When developing Spring Boot JDBC applications, you might encounter the following error:

Terminal window
> Task :app3:bootRun FAILED
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.2.RELEASE)
2020-11-21 16:42:47.957 INFO 63354 --- [ main] com.bswen.app3.Main : No active profile set, falling back to default profiles: default
2020-11-21 16:42:48.268 INFO 63354 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JDBC repositories in DEFAULT mode.
2020-11-21 16:42:48.283 INFO 63354 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10ms. Found 0 JDBC repository interfaces.
2020-11-21 16:42:48.459 ERROR 63354 --- [ main] com.zaxxer.hikari.HikariConfig : Failed to load driver class com.mysql.cj.jdbc.Driver from HikariConfig class classloader sun.misc.Launcher$AppClassLoader@2a139a55
2020-11-21 16:42:48.460 WARN 63354 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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.context.properties.bind.BindException: Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource
2020-11-21 16:42:48.467 INFO 63354 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-11-21 16:42:48.471 ERROR 63354 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:
Property: driver-class-name
Value: com.mysql.cj.jdbc.Driver
Origin: "driverClassName" from property source "source"
Reason: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
Action:
Update your application's configuration
Execution failed for task ':app3:bootRun'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

Environment

  • MySQL 5.1
  • Spring Boot 2.3

Reason

You are using the latest Spring Boot version to connect to an older MySQL version. According to this post by Andreas, the reason is:

Since Spring Boot was expecting a newer MySQL Java Connector, which has been renamed to com.mysql.cj.jdbc.Driver, I also had to add the Spring DataSource driver-class-name setting in my Spring Boot DB config.

Solution

To resolve this issue, you need to configure Spring Boot to use the correct JDBC driver for your MySQL version.

Step 1: Update application.properties

Specify the correct driver class name for MySQL 5.1 in your application.properties file:

application.properties
spring.datasource.driver-class-name: com.mysql.jdbc.Driver

Step 2: Update Runtime Dependency

Ensure that your build.gradle file includes the correct MySQL JDBC driver version:

build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
runtimeOnly 'mysql:mysql-connector-java:5.1.40'
}

You can download the complete example code from GitHub.

Summary

In this post, we explored how to resolve the “Failed to bind properties under ” to com.zaxxer.hikari.HikariDataSource” error in Spring Boot applications. The key steps involve configuring the correct MySQL JDBC driver in your application.properties file and ensuring the runtime dependency matches your MySQL server version. By following these steps, you can avoid compatibility issues and ensure your Spring Boot application connects seamlessly to older MySQL databases.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!