默认的HikariCP连接池启动Spring Boot应用程序 [英] Default HikariCP connection pool starting Spring Boot application

查看:132
本文介绍了默认的HikariCP连接池启动Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的版本为:2.1.6.RELEASE,它来自于我的pom.xml-dependencies中的Spring Boot. 为了连接到我的数据库,我在application.properties中添加了以下内容:

I'm using version: 2.1.6.RELEASE form Spring Boot in my pom.xml-dependencies. To connect to my database I put following in application.properties:

spring.datasource.url= jdbc:postgresql://
spring.datasource.username=
spring.datasource.password=

使用以下方法检查postgresql中的连接数时:

When checking the amount of connections in postgresql with:

SELECT * FROM pg_stat_activity;

我每次启动应用程序时都会看到10个连接.它们几乎都具有相同的查询:

I see each time I start the application exactly 10 connections are made. They almost all have the same query:

SET application_name = 'PostgreSQL JDBC Driver'

是否有一种方法可以防止应用程序建立那么多连接? 我应该自己进行池配置吗? 我的Java应用程序中的哪些资源会初始化这些连接?

Is there a way to prevent the application of making that many connections? Should I make my own pool-configuration? What resource in my Java-application does initialize these connections?

我唯一能想到的是,我使用@Autowired注释EntityManager创建了EntityManager,来自:

The only thing I can think of is that I create EntityManager(s) with the @Autowired annotation, EntityManager from:

javax.persistence.EntityManager;

但是我读到您应该只在使用EntityManagerFactory时关闭此连接.注释应关闭连接.

But I read you should only close the connection this makes when using an EntityManagerFactory. The annotation should close the connection.

如果您需要更多信息,我可以编辑我的帖子

If you would require more info, I could edit my post

推荐答案

这不是连接泄漏,而是所需的行为. Spring Boot Data使用HikariCP作为连接池.

That's no a connection leak but the desired behavior. Spring Boot Data uses HikariCP as a connection pool.

您可以将最大池大小配置为属性.例如:

You can configure the max pool size as property. For example:

spring.datasource.hikari.maximum-pool-size=5

这篇关于默认的HikariCP连接池启动Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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