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

后端 未结 3 1575
时光取名叫无心
时光取名叫无心 2021-02-07 20:47

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. co

3条回答
  •  野的像风
    2021-02-07 21:12

    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')
    

提交回复
热议问题