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?
In Spring Boot 2, Hikari is the default DataSource implementation.
The default connection pool in Spring Boot 2 is HikariCP. It provides enterprise-ready features and better performance. HikariCP is a JDBC DataSource implementation that provides a connection pooling mechanism. If the HikariCP is present on the classpath, the Spring Boot automatically configures it.
You don't need to call DataSource's close() for every connection: Shutdown the DataSource and its associated pool. Thank you very much for your explanation. So, it's okay to call close() only during the application termination and not after every Connection is closed?
Description. Generic defaults. spring.datasource.hikari.maximum-pool-size=50. Specifies number of database connections between database and application. This property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With