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

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

问题描述

我已将Spring Boot应用程序迁移到2.0,并发现hikari连接池存在一些问题.当我获取数据库数据时,这导致hikari cp超时,即.连接不可用.我不知道为什么在以前的版本中它可以正常工作.

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.

因此,我尝试在application.yml中的此配置中使用tomcat池,但是它不起作用(正确的YAML格式).

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

我的pom.xml具有与数据库相关的以下依赖关系:

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

spring-boot-jpa
spring-boot-jdbc
jdbc7

如何排除hikari并使用tomcat连接池?

How to exclude hikari and use tomcat connection pool?

推荐答案

我已经找到解决方案. 可以通过以下修改在pom.xml中解决该问题:

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>

但是,hikari问题可能与默认的连接池小尺寸有关.因此,通过此更改也可以解决此问题,但我自己无法验证.只是为别人注意.像这样的东西:

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天全站免登陆