I have a class mapped as a prototype-bean like this in my web-application:
this class is "linked" to its parent (via parent-property)Code:public class Level { //various properties-fields .... private Level parent; public Level getParent() { return parent; } public void setParent(Level parent) { this.parent = parent; } }
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:
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.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 #########################################################
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


Reply With Quote