Announcement Announcement Module
Collapse
No announcement yet.
are beans from the xml updatable? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • are beans from the xml updatable?

    my case is like this, i define data in my xml for testing i.e. HashMap, ArrayList, Simple Beans and the like, i have no problem getting the values.

    now can i change the values of those defined in the xml?

    for example i defined
    Code:
    <bean id="list" class="java.util.ArrayList">
         <constructor-arg>
                <list>
                        <value>1</value>
                        <value>5</value>
                        <value>3</value>
                </list>
         </construnctor-arg>
    </bean>
    and in my code i did this:
    Code:
    List list = (List) applicationContext.getBean("list");
    list.set(1,"2"); // change index 2 w/c is 5 to 2.
    will the next retrieve of applicationContext.getBean("list") will return 1,2,3? of the original 1,5,3?

    thanks

  • #2
    1,2,3 if your bean is singleton
    1,5,3 if your bean is protoype

    Comment


    • #3
      when you say prototype, do you mean singleton="false"?

      i believe by default spring creates the bean as singleton, i.e. singleton="true"

      so what your saying is true, the value of the list will really be 1,2,3?

      thanks.

      Comment


      • #4
        Yes.

        Cheers.

        Comment


        • #5
          These are the type of questions where you can try 'coding' the answer yourself.

          Comment

          Working...
          X