Configuring HikariCP in Spring Boot

Learn how to integrate HikariCP in the Spring Boot application.

Thanh Tran
Feb 20 · 2 min read

In order to increase the performance while accessing data from a database, we must consider applying the connection-pool. You can search to know how does it help to increase the performance. I already wrote an article about this here:

In this article, I would like to share how we use the HikariCP library in a Spring Boot application.

Why HikariCP?

HikariCP is a lightweight connection-pool library. This library is also known as the fastest connection pool library. “, , , ” are four words used to describe it. At the time I’m writing this article it has more than 63.3k repositories are using it and has 114 contributors reported by GitHub stats.

Image for post
Image for post
Image for post
Image for post
JMH Benchmarks(Source: github.com)
Image for post
Image for post
Screenshot at https://github.com/brettwooldridge/HikariCP#family-user-testimonials

Configuring HikariCP in Spring Boot

With Spring Boot we don’t need to do much to get HikariCP ready for our application. Spring has the autoconfigure module that does all the tasks for us. we only need to include spring-boot-starter-data-jpa or spring-boot-starter-jdbc dependency to the application.

By default, HikariCP will be present at classpath if we include therefor DataSourceAutoConfiguration class will detect the HikariDataSource class presenting then initialize the necessary beans.

So what do we need to configure? The only required property is datasource-related property:

# application.propertiesspring.datasource.username=demo
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo

If you want to change the default value we can add more properties starting with spring.datasource.hikari. All the available properties we can find at com.zaxxer.hikari.HikariConfig

An example:

# application.propertiesspring.datasource.hikari.pool-name=ps-demo
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.idle-timeout=30000

Verify our works

Take at the application log we should have the log following screenshot:

Image for post
Image for post

To enable debug log for HikariCP we can add the following configuration to the application.properties

logging.level.com.zaxxer.hikari.HikariConfig=DEBUG
logging.level.com.zaxxer.hikari=DEBUG

Programming Sharing

We write about programming. We share about programming.

Sign up for Programming Sharings Newsletter

By Programming Sharing

Get new articles update by signing up our newsletter Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Thanh Tran

Written by

Software Engineer at Terralogic. Blogger and Amateur Investor

Programming Sharing

The publication to share programming knowledge

Thanh Tran

Written by

Software Engineer at Terralogic. Blogger and Amateur Investor

Programming Sharing

The publication to share programming knowledge

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store