如何在 Spring Boot 2.0 上将默认 hikari cp 替换为 tomcat 池 [英] How to replace default hikari cp to tomcat pool on spring boot 2.0

查看:46
本文介绍了如何在 Spring Boot 2.0 上将默认 hikari cp 替换为 tomcat 池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

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

这篇关于如何在 Spring Boot 2.0 上将默认 hikari cp 替换为 tomcat 池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆