Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace default hikari cp to tomcat pool on spring boot 2.0

I have migrated spring boot application to 2.0 and found out some problems with hikari connection pool. When I am fetching database data this results to hikari cp timeout ie. connection is not available. I don't know why when in the previous version this worked correctly.

Therefore I tried to use tomcat pool with this config in application.yml but it did not work (in correct YAML formatting).

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

My pom.xml has these dependencies related to DB things:

spring-boot-jpa
spring-boot-jdbc
jdbc7

How to exclude hikari and use tomcat connection pool?

like image 281
Luke Avatar asked May 04 '18 10:05

Luke


People also ask

Does spring boot use Hikari by default?

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

What is the default connection pool in spring boot?

The default connection pool in Spring Boot 2 is HikariCP. It provides enterprise-ready features and better performance. HikariCP is a JDBC DataSource implementation that provides a connection pooling mechanism. If the HikariCP is present on the classpath, the Spring Boot automatically configures it.

How do I turn off Hikari connection pool?

You don't need to call DataSource's close() for every connection: Shutdown the DataSource and its associated pool. Thank you very much for your explanation. So, it's okay to call close() only during the application termination and not after every Connection is closed?

What is default Hikari pool size?

Description. Generic defaults. spring.datasource.hikari.maximum-pool-size=50. Specifies number of database connections between database and application. This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections.


1 Answers

I have found out the solution. This can be resolved in pom.xml by modifying like that:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jdbc</artifactId>
</dependency>

However the hikari problem was probably with default small size of connection pool. So this problem could be resolved also with this change but not verified by myself. Just note for others. Something like that:

spring.datasource.hikari.connection-timeout=60000
spring.datasource.hikari.maximum-pool-size=5
like image 127
Luke Avatar answered Nov 10 '22 21:11

Luke