Results 1 to 5 of 5

Thread: prototype strange behaviour

  1. #1
    Join Date
    Nov 2006
    Posts
    218

    Default prototype strange behaviour

    I have a class mapped as a prototype-bean like this in my web-application:

    Code:
    public class Level {
    //various properties-fields
    ....
    private Level parent;
    
    public Level getParent() {
    		return parent;
    	}
    
    public void setParent(Level parent) {
    		this.parent = parent;
    }
    }
    this class is "linked" to its parent (via parent-property)

    a class-factory builds it with "implements ApplicationContextAware"

    Level level = (Level) this.applicationContext.getBean("level");

    and relative parent is injected.

    In an integration test is "simulated" many times up and down on same level, and parent keeps its "original" memory-address. That's test-log:

    Code:
    BUILD FIRST TIME PARENT-LEVEL : org.myapp.Level@1a9d1b
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@1cc5069
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@1636e4e
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@12c8fa8
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@10deb5f
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@1367e28
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@b4be3d
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@1c1ac46
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@5a3923
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@e3570c
    #########################################################
    PARENT-LEVEL : org.myapp.Level@1a9d1b
    NEW-LEVEL : org.myapp.Level@bf1d3b
    #########################################################
    how you can see, everytime it does an up & down, parent remains same and a new level instance is build (and so you have one-parent and many level-children). This is the correct situation.

    Running my application in Jetty, parent address change at third "up & down"!!!!

    what's problem??? prototype-scope is not good for my situation???

    Thanks,
    Julio

  2. #2
    Join Date
    Apr 2006
    Location
    Canada
    Posts
    164

    Default

    Is the injected parent a prototype bean as well?
    Chris Lee (blog)
    Principal Consultant
    Digital Ascent Inc.

  3. #3
    Join Date
    Nov 2006
    Posts
    218

    Default

    yes, a prototype-"level" is injected in a prototype-"level"

  4. #4
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    I don't get your problem. Can you show the snippet of the XML and when/where/how/what code you execute for your test?

    Joerg
    This post can contain insufficient information.

  5. #5
    Join Date
    Nov 2006
    Posts
    218

    Default

    sorry, problem solved.

    It was rise up in integration, but was not related to spring

Posting Permissions

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