This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: when spring prototype beans are not prototypes
Feed Title: Logemann Blog
Feed URL: http://feeds.feedburner.com/LogemannBlog
Feed Description: Marc Logemann's thoughts on java and other stuff
One thing i really would like to see in spring is a more natural approach for declaring prototype beans when used by singleton beans. To be more detailed. When spring managed Bean A is a singleton and is using Bean B wich is a prototype (which is injected via setter injection), then its of course not enough to just tell spring that Bean B has scope “prototype”. Now everyone could argue that this is obvious and thus a no brainer because Bean A will always hold the same instance of Bean B due to the fact that the setter will be invoked only once throughout the entire lifetime. Even though its obvious for spring veterans, the forums speak a different story, just search for the word prototype and you will see plenty of questions in that area.
I am aware of Lookup-Method Injection which addresses exactly that problem, but even better would be a more automatic approach. I would like to use the same config semantics as with regular setter injection, spring should be doing the hard work for us. We already told spring what we want in form of describing how beans should be created and how they are wired together.