Announcement Announcement Module
No announcement yet.
BeanFactory lifecycle? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanFactory lifecycle?

    Do BeanFactories have explicit lifecycles? The documentation
    (1.1 RC2) on Bean Lifecycles in Section 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?

  • #2
    If it's an ApplicationContext, you can cast to ConfigurableApplicationContext:

    and take it away from there...



    • #3
      Got it, thanks!


      • #4
        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).


        • #5
          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.