Spring Boot – Which connection pool is used?

1. Overview

In this article, we will check which connection pool is being used in our Spring Boot application. In Spring Boot, By annotating with @Autowired for the javax.sql.DataSource, we can get which database connection pool is using in the currently running application.

2. Tomcat pooling – Default

Here’s the program to print the current database connection pool

The output will be Tomcat pooling by default.

Current DataSource = org.apache.tomcat.jdbc.pool.DataSource@3d3e5463

3. Commons DBCP

To switch to other connection pool, Ex: Commons DBCP, we need to exclude the default(tomcat) and include the Commons DBCP in the dependency classpath.

After changing the pom and update maven project, Run the above SBConsoleApplication. The output will be like below.

Current DataSource = org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy@1817f1eb

Thank you.





Click Here to Leave a Comment Below 0 comments