Issue Details (XML | Word | Printable)

Key: SPR-3509
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Rick Evans
Reporter: Marc Logemann
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

better docs for "3.4.2. The prototype scope" wrt using them with singleton beans

Created: 22/May/07 05:10 PM   Updated: 23/May/07 10:39 AM
Component/s: SpringCORE
Affects Version/s: None
Fix Version/s: 2.1 M2

Time Tracking:
Not Specified


 Description  « Hide
When you only read the contents of the chapter 3.4.2, you can get the impression that just defining prototype gets unique instances of a bean, in whatever context. Of course this is not true when using them within a singleton bean via method injection. It would be a time saver and a forum posts saver to make a hint to "3.3.8.1. Lookup method injection" directly in the description of what a prototype bean is.

Of course also some note that prototype has no effect when used by singleton beans in method injection mode would be nice.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Rick Evans added a comment - 23/May/07 09:58 AM
Fixed. Thanks for raising this... I've added a small section to the end of the prototype section that explains the issue and has a link to the method injection section.

Cheers
Rick

Taras Tielkes added a comment - 23/May/07 10:07 AM
What about the example used the manual to describe the "prototype" scope..

Does such a configuration (injecting prototypes into singletons using ctor/setter) actually *ever* make sense? I'm just curious if I'm missing some potential usage pattern.

Rick Evans added a comment - 23/May/07 10:23 AM
Hi Taras

Good point... off the top of my head I can't think of a single really good use case.

Maybe Juergen knows some... in all my years of using Spring, I have never just injected a raw prototype in a raw singleton... so yeah, unless Juergen comments before this evening, I'll go add a note about that to the section that I just added.

Cheers
Rick

Taras Tielkes added a comment - 23/May/07 10:39 AM
Hi Rick,

I haven't seen such usage either.
However, consider the example of a bean that implements a cache. Declaring one cache bean (with "prototype" scope) and injecting that dependency (using ctor/setter) into other beans will give each bean a unique, isolated cache instance.

For the sake of readability I would prefer multiple (inner) cache bean declarations, but above pattern might actually be valid (but confusing).