Default HikariCP connection pool starting Spring Boot application Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Default HikariCP connection pool starting Spring Boot application without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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=

When checking the amount of connections in postgresql with:

SELECT * FROM pg_stat_activity;

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'

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?

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

javax.persistence.EntityManager;

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

Answer

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
We are here to answer your question about Default HikariCP connection pool starting Spring Boot application - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji