Results 1 to 3 of 3

Thread: Refreshing spring managed beans

  1. #1
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    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

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. Replies: 0
    Last Post: Aug 25th, 2005, 05:11 AM
  3. Comparision JMX Spring
    By umeshs79 in forum Container
    Replies: 5
    Last Post: Jun 16th, 2005, 12:27 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 0
    Last Post: Sep 2nd, 2004, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •