spring-boot
spring-boot copied to clipboard
Spring devtools not shutdown connection pool on restart
I'm having trouble with spring-devtools. My application uses Spring JPA with HikariCP. The problem occurs when the application restarts because the connections are not terminated and all connections remain open.
Thanks for the report. Unfortunately it does not contain enough information for us to diagnose the problem. For example, you haven't told us what version of Spring Boot you're using or how you have configured Hikari. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Thanks for the report. Unfortunately it does not contain enough information for us to diagnose the problem. For example, you haven't told us what version of Spring Boot you're using or how you have configured Hikari. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Thank you, @wilkinsona. Apologies for the inadequate details in my initial description. Here is a link to a simple demo repository: https://github.com/pascencio/spring-dev-tools-issue
I conducted some tests and it seems that the issue may occur when using AbstractRoutingDataSource.
Thanks in the advance!
it seems that the issue may occur when using AbstractRoutingDataSource
Yes, that's the problem. The DataSource
s that your MultiTenantDataSource
is using are not beans so the application context does not know about them and does not know that they need to be closed. You could either expose them as beans or you could change MultiTenantDataSource
to implement DisposableBean
and close each of its targets when it is destroyed.
Note that this isn't a Devtools-specific problem. The target DataSource
s will also not be closed when the application is shut down normally.
it seems that the issue may occur when using AbstractRoutingDataSource
Yes, that's the problem. The
DataSource
s that yourMultiTenantDataSource
is using are not beans so the application context does not know about them and does not know that they need to be closed. You could either expose them as beans or you could changeMultiTenantDataSource
to implementDisposableBean
and close each of its targets when it is destroyed.Note that this isn't a Devtools-specific problem. The target
DataSource
s will also not be closed when the application is shut down normally.
Thanks, @wilkinsona! I tweaked my code based on your suggestions—switched my MultiTenantDataSource to Component
and implemented DisposableBean
. Now it ensures all connections close properly during the shutdown process.