<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSpring%2FIoC_Shutdown</id>
		<title>Java/Spring/IoC Shutdown - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSpring%2FIoC_Shutdown"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Shutdown&amp;action=history"/>
		<updated>2026-04-21T13:41:19Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Spring/IoC_Shutdown&amp;diff=6565&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Shutdown&amp;diff=6565&amp;oldid=prev"/>
				<updated>2010-06-01T06:16:31Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:16, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Spring/IoC_Shutdown&amp;diff=6564&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Spring/IoC_Shutdown&amp;diff=6564&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:44Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Dispose Interface ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: disposeMethod.xml&lt;br /&gt;
&amp;lt;!DOCTYPE beans PUBLIC &amp;quot;-//SPRING//DTD BEAN//EN&amp;quot; &amp;quot;http://www.springframework.org/dtd/spring-beans.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;beans&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;destructiveBean&amp;quot; class=&amp;quot;DestructiveBeanWithInterface&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;filePath&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;c:/test.txt&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
    &amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBean implements InitializingBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.DisposableBean;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBeanWithInterface implements InitializingBean,&lt;br /&gt;
        DisposableBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        ConfigurableListableBeanFactory factory = new XmlBeanFactory(&lt;br /&gt;
                new FileSystemResource(&lt;br /&gt;
                        &amp;quot;build/disposeInterface.xml&amp;quot;));&lt;br /&gt;
        DestructiveBeanWithInterface bean = (DestructiveBeanWithInterface) factory.getBean(&amp;quot;destructiveBean&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot;Calling destroySingletons()&amp;quot;);&lt;br /&gt;
        factory.destroySingletons();&lt;br /&gt;
        System.out.println(&amp;quot;Called destroySingletons()&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}         &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Shutdown Hook Bean Example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: shutdownHookBean.xml&lt;br /&gt;
&amp;lt;!DOCTYPE beans PUBLIC &amp;quot;-//SPRING//DTD BEAN//EN&amp;quot; &amp;quot;http://www.springframework.org/dtd/spring-beans.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;beans&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;destructiveBean&amp;quot; class=&amp;quot;DestructiveBeanWithInterface&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;filePath&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;c:/test.txt&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
    &amp;lt;/bean&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;shutdownHook&amp;quot; class=&amp;quot;ShutdownHookBean&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.DisposableBean;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBeanWithInterface implements InitializingBean,&lt;br /&gt;
        DisposableBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import org.springframework.beans.BeansException;&lt;br /&gt;
import org.springframework.beans.factory.BeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.BeanFactoryAware;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
public class ShutdownHookBean implements BeanFactoryAware,&lt;br /&gt;
        Runnable {&lt;br /&gt;
    private ConfigurableListableBeanFactory factory;&lt;br /&gt;
    public void setBeanFactory(BeanFactory factory) throws BeansException {&lt;br /&gt;
        if (factory instanceof ConfigurableListableBeanFactory) {&lt;br /&gt;
            this.factory = (ConfigurableListableBeanFactory) factory;&lt;br /&gt;
            Runtime.getRuntime().addShutdownHook(new Thread(this));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void run() {&lt;br /&gt;
        if (factory != null) {&lt;br /&gt;
            System.out.println(&amp;quot;Destroying Singletons&amp;quot;);&lt;br /&gt;
            factory.destroySingletons();&lt;br /&gt;
            System.out.println(&amp;quot;Singletons Destroyed&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBean implements InitializingBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class ShutdownHookBeanExample {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        ConfigurableListableBeanFactory factory = new XmlBeanFactory(&lt;br /&gt;
                new FileSystemResource(&lt;br /&gt;
                        &amp;quot;build/shutdownHook.xml&amp;quot;));&lt;br /&gt;
        // make sure the shutdown hook is created&lt;br /&gt;
        factory.preInstantiateSingletons();&lt;br /&gt;
        DestructiveBeanWithInterface bean = (DestructiveBeanWithInterface) factory.getBean(&amp;quot;destructiveBean&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Shutdown Hook Example ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
Pro Spring&lt;br /&gt;
By Rob Harrop&lt;br /&gt;
Jan Machacek&lt;br /&gt;
ISBN: 1-59059-461-4&lt;br /&gt;
Publisher: Apress&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
//File: disposeInterface.xml&lt;br /&gt;
&amp;lt;!DOCTYPE beans PUBLIC &amp;quot;-//SPRING//DTD BEAN//EN&amp;quot; &amp;quot;http://www.springframework.org/dtd/spring-beans.dtd&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;beans&amp;gt;&lt;br /&gt;
    &amp;lt;bean id=&amp;quot;destructiveBean&amp;quot; class=&amp;quot;DestructiveBeanWithInterface&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;property name=&amp;quot;filePath&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;c:/test.txt&amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/property&amp;gt;&lt;br /&gt;
    &amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;lt;/beans&amp;gt;&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
public class ShutdownHook implements Runnable {&lt;br /&gt;
    private ConfigurableListableBeanFactory factory;&lt;br /&gt;
    &lt;br /&gt;
    public ShutdownHook(ConfigurableListableBeanFactory factory) {&lt;br /&gt;
        this.factory = factory;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    public void run() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Singletons&amp;quot;);&lt;br /&gt;
        factory.destroySingletons();&lt;br /&gt;
        System.out.println(&amp;quot;Singletons Destroyed&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.DisposableBean;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBeanWithInterface implements InitializingBean,&lt;br /&gt;
        DisposableBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        ConfigurableListableBeanFactory factory = new XmlBeanFactory(&lt;br /&gt;
                new FileSystemResource(&lt;br /&gt;
                        &amp;quot;build/disposeInterface.xml&amp;quot;));&lt;br /&gt;
        DestructiveBeanWithInterface bean = (DestructiveBeanWithInterface) factory.getBean(&amp;quot;destructiveBean&amp;quot;);&lt;br /&gt;
        System.out.println(&amp;quot;Calling destroySingletons()&amp;quot;);&lt;br /&gt;
        factory.destroySingletons();&lt;br /&gt;
        System.out.println(&amp;quot;Called destroySingletons()&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import org.springframework.beans.factory.InitializingBean;&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class DestructiveBean implements InitializingBean {&lt;br /&gt;
    private InputStream is = null;&lt;br /&gt;
    public String filePath = null;&lt;br /&gt;
    public void afterPropertiesSet() throws Exception {&lt;br /&gt;
        System.out.println(&amp;quot;Initializing Bean&amp;quot;);&lt;br /&gt;
        if (filePath == null) {&lt;br /&gt;
            throw new IllegalArgumentException(&lt;br /&gt;
                    &amp;quot;You must specify the filePath property of &amp;quot; + DestructiveBean.class);&lt;br /&gt;
        }&lt;br /&gt;
        is = new FileInputStream(filePath);&lt;br /&gt;
    }&lt;br /&gt;
    public void destroy() {&lt;br /&gt;
        System.out.println(&amp;quot;Destroying Bean&amp;quot;);&lt;br /&gt;
        if (is != null) {&lt;br /&gt;
            try {&lt;br /&gt;
                is.close();&lt;br /&gt;
                is = null;&lt;br /&gt;
            } catch (IOException ex) {&lt;br /&gt;
                System.err.println(&amp;quot;WARN: An IOException occured&amp;quot;&lt;br /&gt;
                        + &amp;quot; trying to close the InputStream&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    public void setFilePath(String filePath) {&lt;br /&gt;
        this.filePath = filePath;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
}&lt;br /&gt;
///////////////////////////////////////////////////////////////////////////////////////&lt;br /&gt;
&lt;br /&gt;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;&lt;br /&gt;
import org.springframework.beans.factory.xml.XmlBeanFactory;&lt;br /&gt;
import org.springframework.core.io.FileSystemResource;&lt;br /&gt;
public class ShutdownHookExample {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
        ConfigurableListableBeanFactory factory = new XmlBeanFactory(&lt;br /&gt;
                new FileSystemResource(&lt;br /&gt;
                        &amp;quot;build/disposeInterface.xml&amp;quot;));&lt;br /&gt;
        Runtime.getRuntime().addShutdownHook(&lt;br /&gt;
                new Thread(new ShutdownHook(factory)));&lt;br /&gt;
        DestructiveBeanWithInterface bean = (DestructiveBeanWithInterface) factory.getBean(&amp;quot;destructiveBean&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>