I want to release a database connection while reloading the context (using Tomcat Manager web app) of a Struts2 Web Application. I am also using Spring and hibernate. (Spring's HibernateTemplate, Spring SessionFactory and Apache Commons-dbcp with HSql standalone-database)
As I am using HSql 'standalone' database, even if the web application context gets reloaded, the database connection is not released while destroying the context. So I get 'Database is already in use by other process' error. I want to know whether there is any way to implement something like "destroy() method of servlet" in a Struts2 application. I am not sure whether I can do it with spring configuration. Any idea? If there are many ways of doing it, kindly also tell which way is the best for me. (1) struts.properties: struts.objectFactory = org.apache.struts2.spring.StrutsSpringObjectFactory (2) applicationContext.xml (my spring configuration file) <beans default-autowire="autodetect"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:file:C:/Projects/db/hsqlTest" /> <property name="username" value="sa"/> <property name="password" value=""/> </bean> <bean id="mySessionFactory" class=" org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource"/> <property name="mappingResources"> <list> <value>no/bbs/webservice/client/config/model/certificate.hbm.xml</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="hibernateTemplate" class=" org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"> <ref bean="mySessionFactory"/> </property> </bean> <bean id="testClientDao" class=" webservice.client.dao.hibernate.TestClientDAO"> <property name="hibernateTemplate"> <ref bean="hibernateTemplate"/> </property> </bean> <!-- Some Strus2-Actions follow --> </beans> (3) web.xml doesn't contain anything but struts2 filter declaration.