Reputation: 21
I am seeing DB connections not being closed upon application shutdown.
We are using Spring org.springframework.jdbc.core.support.JdbcTemplate, and have configured a connection pool. Example Context xml for Tomcat is this:
<Resource name="jdbc/fooResource"
auth="Container"
testOnBorrow="true"
validationQuery="select 1 from DUAL"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
username="user"
password="password"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/myschema"
maxActive="100"
maxIdle="10"/>
My Spring bean definition has this snippet:
<jee:jndi-lookup id = "dataSource"
jndi-name = "jdbc/fooResource"
expected-type = "javax.sql.DataSource"/>
Observations:
Questions:
Thanks.
Upvotes: 2
Views: 3565
Reputation: 8202
If you create the application context manually, you need to register a shutdown hook on the application context. When you start the app, get a reference to the context and add this line
context.registerShutdownHook();
If you don't do this, destruction events aren't triggered.
Upvotes: 2