PDA

View Full Version : BeanFactory lifecycle?


swruch
Aug 23rd, 2004, 03:23 PM
Do BeanFactories have explicit lifecycles? The documentation
(1.1 RC2) on Bean Lifecycles in Section 3.4.1.2 says that
"Implementing the ...DisposableBean interface allows a bean to
get a callback when the BeanFactory containing it is destroyed."

I'm looking for something like BeanFactory.shutdown() / stop() / dispose()
or some other way to take the BeanFactory down so that it can
be reconfigured and restarted. I'm looking through the APIs, but
I'm not finding anything.

I figure I must be missing something here as other frameworks /
containers have some notion of a lifecycle for the container.

How does this work in Spring?

Colin Sampaleanu
Aug 23rd, 2004, 03:43 PM
If it's an ApplicationContext, you can cast to ConfigurableApplicationContext:

http://www.springframework.org/docs/api/org/springframework/context/ConfigurableApplicationContext.html

and take it away from there...

Regards

swruch
Aug 23rd, 2004, 04:08 PM
Got it, thanks!

sethladd
Aug 28th, 2004, 11:38 PM
If none of my beans want to be notified of the shutdown callback, is there any reason why I want to shutdown() formally the BeanFactory/ApplicationContext? I ask just to be safe. :)

Currently, in my tests, I'm just setting my application context to null in the tearDown() method.

Just want to do The Right Thing (tm). :)

rhasselbaum
Feb 23rd, 2006, 01:57 PM
I'm wrestling with this question, too, and would appreciate some advice. In my case, I'm using an XmlBeanFactory as a lightweight container for a group of "short-term" Data Access Objects. The JDBC connection pool library I'm using (C3P0) uses background threads to manage connections, and I need to be able to shut those down on-demand in the application.

Up to now, I have been letting the bean factory go out of scope when I don't care about it anymore, but apparently, this is not sufficient to end the connection pool threads.

So how do I shut down an XmlBeanFactory properly? There is no close method that I can see.

Thanks!