Announcement Announcement Module
Collapse
No announcement yet.
Refreshing spring managed beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Refreshing spring managed beans

    In my application, some of the singleton beans are initialized with information from the database. We are using an administration tool to refresh our cached data, but this only helps our DAO's. Is there an easy way to get all of the beans in the spring container to reinitialize themselves without restarting the servlet container? Thanks.

    Karl

  • #2
    You can get the context, then cast it to ConfigurableApplicationContext, on which you can call refresh(). This will force a re-init. You should be careful when and how you do this though. Obviously if you're in an a web app serving multiple request threads the result can be unpredictable, depending on the usecase and the objects in there. Just as an example, an object which is in the middle of being used, could be holding a reference to another object which has a defined lifecycle (destroy method, etc.), and still try to use it after that other object thinks it is destroyed...

    Comment


    • #3
      Hmmm.. you're right. It does seem unpredictable. I think the behaviour I really want is that existing requests continue to use the old application context, while a new application context is being created. Once the new application context has been successfully created, we can swap that in for all new requests to the application. Is this a possibility?

      Thanks for your help!

      Karl

      Comment

      Working...
      X