Persistence top

The early-bird price of the new Learn Spring Data JPA course is increasing by $35 on March 12:


1. Overview

Hikari is a JDBC DataSource implementation that provides a connection pooling mechanism.

Compared to other implementations, it promises to be lightweight and better performing. For an introduction to Hikari, see this article.

This quick tutorial shows how we can configure a Spring Boot 2 or Spring Boot 1 application to use the Hikari DataSource.

Further reading:

One-to-One Relationship in JPA

Learn three different ways to maintain a one-to-one relationship with JPA.

Spring Boot with Hibernate

A quick, practical intro to integrating Spring Boot and Hibernate/JPA.

2. Configuring Hikari With Spring Boot 2.x

In Spring Boot 2, Hikari is the default DataSource implementation.

This is what's changed from Spring Boot 1.x:

  • the dependency to Hikari is now automatically included in spring-boot-starter-data-jpa and spring-boot-starter-jdbc
  • the discovery algorithm that automatically determines a DataSource implementation now prefers Hikari over TomcatJDBC (see the reference manual).

Thus, we have nothing to do if we want to use Hikari in an application based on Spring Boot 2.x.

3. Tuning Hikari Configuration Parameters

One of Hikari's advantages over other DataSource implementations is the fact that it offers a lot of configuration parameters.

We can specify the values for these parameters by using the prefix spring.datasource.hikari and appending the name of the Hikari parameter:


A list of all Hikari parameters with a good explanation is available on the Hikari Github Site, as well as in the Spring docs.

4. Configuring Hikari With Spring Boot 1.x

Spring Boot 1.x uses the Tomcat JDBC Connection Pool by default.

As soon as we include spring-boot-starter-data-jpa into our pom.xml, we'll transitively include a dependency to the Tomcat JDBC implementation. During runtime, Spring Boot will then create a Tomcat DataSource for us to use.

To configure Spring Boot to use the Hikari Connection Pool instead, we have two options.

4.1. Maven Dependency

First, we need to include the dependency on Hikari in our pom.xml:


The most current version can be found on Maven Central.

4.2. Explicit Configuration

The safest way to tell Spring Boot to use Hikari is configuring the DataSource implementation explicitly.

To do this, we simply set the property spring.datasource.type to the fully-qualified name of the DataSource implementation we want to use:

    properties = "spring.datasource.type=com.zaxxer.hikari.HikariDataSource"
public class HikariIntegrationTest {

    private DataSource dataSource;

    public void hikariConnectionPoolIsConfigured() {
        assertEquals("com.zaxxer.hikari.HikariDataSource", dataSource.getClass().getName());

4.3. Removing the Tomcat JDBC Dependency

The second option is to let Spring Boot find the Hikari DataSource implementation itself.

If Spring Boot cannot find the Tomcat DataSource in the classpath, it will automatically look for the Hikari DataSource next. The discovery algorithm is described in the reference manual.

To remove the Tomcat Connection Pool from the classpath we can exclude it in our pom.xml:


Now, the test from the previous section will also work without setting the spring.datasource.type property.

5. Conclusion

In this article, we've configured the Hikari DataSource implementation in a Spring Boot 2.x application and learned how to leverage Spring Boot's autoconfiguration. We've also had a look at the changes required to configure Hikari when using Spring Boot 1.x.

The code for the Spring Boot 1.x example is available here, and the code for the Spring Boot 2.x example is available here.

Persistence bottom

The early-bird price of the new Learn Spring Data JPA course is increasing by $35 on March 12:

1 Comment
Inline Feedbacks
View all comments
Comments are closed on this article!