Results 1 to 5 of 5

Thread: are beans from the xml updatable?

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    1,2,3 if your bean is singleton
    1,5,3 if your bean is protoype
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default

    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.

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Yes.

    Cheers.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    These are the type of questions where you can try 'coding' the answer yourself.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

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