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

  • update spring managed bean at runtime

    Hi,
    I want to change the properties of a bean defined in the spring application context at runtime. How can I accomplish this?
    Thanks

  • #2
    Re: update spring managed bean at runtime

    Originally posted by mavisakal
    Hi,
    I want to change the properties of a bean defined in the spring application context at runtime. How can I accomplish this?
    Thanks
    In my Ant Spring project I used the technique given at:
    http://forum.springframework.org/showthread.php?t=12401

    Worked ok.
    Last edited by robyn; May 14th, 2006, 12:51 PM.

    Comment


    • #3
      Thanks jbetancourt,
      My Spring defined bean has a property of type TreeMap. I want to change the values in this TreeMap at runtime. This treemap contains values which are retrieved from database. I dont want to access database everytime. I want to change the values in treeMap when the data in the database table changed. So if I get the bean from the Spring context as shown in your message:
      Code:
      Object bean = context.getBean(beanName);
      and change the property(TreeMap), would it be Springish(I mean would there be a problem).
      Thanks

      Comment


      • #4
        From the little I know, that would seem to be the correct approach for singleton beans. Since the object is singleton, a simple setting of properties would be enough, but as mentioned in the referenced post, we want to allow the container to do its stuff.

        Not sure about non-singleton beans. If these are obtained from the container, won't they just get the default configuration property values? Thus, any new changes (as in your example) would be lost!

        Come to think of it, if bean container is recycled or beans are allowed to be reinitialized this is true for singleton beans also. So, serialization, as in original JavaBean vision may be neccessary.

        Comments from Spring experts?

        Perhaps, just making the potentially db modified treemap into its own bean would be a possible approach. A dirty bit could trigger a lifecycle event. Just thinking out loud.

        Comment

        Working...
        X