File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Request scope vs Prototype scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Request scope vs Prototype scope" Watch "Request scope vs Prototype scope" New topic
Author

Request scope vs Prototype scope

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi ,

Whats the difference b/w request scope vs prototype scope in terms of a webapplication..where there are 2 beans
1 is request scope
1 is prototype bean...
And both end up being used for the processing...

For x request...x request beans & x prototype beans are created ..so what is the difference between the two..

Regards
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

A Kumar wrote:Hi ,

Whats the difference b/w request scope vs prototype scope in terms of a webapplication..where there are 2 beans
1 is request scope
1 is prototype bean...
And both end up being used for the processing...

For x request...x request beans & x prototype beans are created ..so what is the difference between the two..

Regards


Prototype creates a brand new instance everytime you call getBean on the ApplicationContext. Whereas for Request, only one instance is created for an HttpRequest. So in a single HttpRequest, I can call getBean twice on Application and there will ever be one bean instantiated, whereas that same bean scoped to Prototype in that same single HttpRequest would get 2 different instances.

HttpRequest scope
Mark mark1 = context.getBean("mark");
Mark mark2 = context.getBean("mark");
mark1 == mark2; //This will return true

Prototype scope

Mark mark1 = context.getBean("mark");
Mark mark2 = context.getBean("mark");
mark1 == mark2; //This will return false


Hope that clears it up for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks Mark!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request scope vs Prototype scope