16

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?

Luke
  • 1,163
  • 2
  • 11
  • 19

3 Answers3

17

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
Luke
  • 1,163
  • 2
  • 11
  • 19
  • still hikari is active – KJEjava48 Jul 17 '19 at 16:21
  • Regarding the pool size increase. It will still not resolve the Hikari problem, Ours is set to 20 min and 100 Max and we get the error sometimes and our production system goes crashing down. – bytor99999 Oct 21 '19 at 15:49
5

Since Spring Boot 2.0 release, spring-boot-starter-jdbc and spring-boot-starter-data-jpa resolve HikariCP dependency by default and spring.datasource.type property has HikariDataSource as default value.So if u have both dependency in your application you should exclude it from both like below.

implementation('org.springframework.boot:spring-boot-starter-data-jpa') {
    exclude group: 'com.zaxxer', module: 'HikariCP'
}
implementation('org.springframework.boot:spring-boot-starter-jdbc') {
    exclude group: 'com.zaxxer', module: 'HikariCP'
}

After that you can configure other pooling technologies that u likes to use, like below . In your application.yml file :

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

In dependency :

implementation('org.apache.tomcat:tomcat-jdbc')
KJEjava48
  • 1,967
  • 7
  • 40
  • 69
0

Also:

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

works with

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jdbc</artifactId>
</dependency>
matzeihnsein
  • 678
  • 7
  • 16