fixed DataSourceInitializer so it executes the destroy scripts on bean destruction
This commit is contained in:
@@ -66,7 +66,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-core</artifactId>
|
||||
<artifactId>com.springsource.org.apache.activemq</artifactId>
|
||||
<version>5.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -51,7 +52,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class DataSourceInitializer implements InitializingBean {
|
||||
public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DataSourceInitializer.class);
|
||||
|
||||
@@ -82,12 +83,6 @@ public class DataSourceInitializer implements InitializingBean {
|
||||
|
||||
private void initialize() {
|
||||
if (!initialized) {
|
||||
if (destroyScripts != null) {
|
||||
for (int i = 0; i < destroyScripts.length; i++) {
|
||||
Resource initScript = initScripts[i];
|
||||
doExecuteScript(initScript);
|
||||
}
|
||||
}
|
||||
if (initScripts != null) {
|
||||
for (int i = 0; i < initScripts.length; i++) {
|
||||
Resource initScript = initScripts[i];
|
||||
@@ -164,4 +159,15 @@ public class DataSourceInitializer implements InitializingBean {
|
||||
this.ignoreFailedDrop = ignoreFailedDrop;
|
||||
}
|
||||
|
||||
public void destroy() throws Exception {
|
||||
if (initialized) {
|
||||
if (destroyScripts != null) {
|
||||
for (int i = 0; i < destroyScripts.length; i++) {
|
||||
Resource destroyScript = destroyScripts[i];
|
||||
doExecuteScript(destroyScript);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
DROP TABLE T_BARS;
|
||||
create table T_BARS (
|
||||
id integer not null primary key,
|
||||
name varchar(80),
|
||||
|
||||
Reference in New Issue
Block a user