• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

What is the difference between prototype and request scope?

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between between prototype and request scope in Spring? Both creates a new instance whenever required.
What if I am using prototype scope in WebLayer? How it will be different from request scope?
 
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a user does a request to the server and if the bean of request scope is asked twice from the spring factory it will return the same object however if bean with prototype scope is asked twice it will return two different object.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lalit.

Is there any advantage of using one over other?
 
Lalit Bhatt
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think two should not be compared. Rather than advantage and disadvantage look into your requirement.

The request scope beans are same as the request scope objects when you are working with plain servlet and JSP. In the prototype case you get a new bean every time you ask for it. In request scope you get the same bean till you are in request scope. Also request scope beans make sense only in web applications. Prorotype scope beans lifecycle are not managed by Spring. See here

If you can tell the real life use case where you want to use this, it will be easier to tell which one to use and why?
 
I'm so happy! And I wish to make this tiny ad happy too:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!