- This depends on how you're instantiating it. I a webapp, this is typically done at context shutdown. On the command line, you have to specifically close the context (via the "close" method on "AbstractApplicationContext"
- Same as anything else that falls out of scope. Not sure if the "close" method is part of the finalizer phase or not. I would hope the finalizer would trigger the destroy phase.
- As someone else said, don't use BeanFactory directly. Create an ApplicationContext. The most common way for web apps is the ContextLoaderListener, and for command line programs would be ClassPathXmlApplicationContext.
// Keep a specific type, so we can call the "close" method later since
it's // not part of the ApplicationContext interface itself.
ClasspathXmlApplicationContext context =
new ClasspathXmlApplicationContext(new String[] { "applicationContext.xml });
and then later on you close it:
context.close();
For webapps:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>