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 Servlet scopes vs. bean scopes in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Servlet scopes vs. bean scopes in Spring" Watch "Servlet scopes vs. bean scopes in Spring" New topic
Author

Servlet scopes vs. bean scopes in Spring

Misi Nyilas
Greenhorn

Joined: Nov 18, 2008
Posts: 3
Hi,
I have some difficulties to map scopes used for servlets (application/session/request/private) to scopes used in Spring(singleton/prototype/request/session/global session). Can anyone offer me some public source where such a comparison/mapping has been described?
Just a few examples: is singleton the same as application scope used for servlets? If yes, what means global session? What are custom created scopes in Spring and how could be mapped to terms used for servlets? Are the request and session scopes in Spring equivalent to those ones used for servlets ore they are just similar? In latter case what are the differences?
I know the terms used in JSP, but I'm a begginner in Spring.
Thanks in advance!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Spring scopes, Session and Request are for HttpSession and HttpRequests. However, they only work in the web environment. If you are running outside a web container it will default back to Singleton.

Singleton means one and only one instance inside the ApplicationContext. Now in the web environment with SPring MVC, there are actually two ApplicationContext's created. One called the parent ApplicationContext which holds your "backend" business logic, service/repository beans. In the second the Web ApplicationContext would have Controllers, ViewResolvers, MappingAdapters and Handlers. The Web ApplicationContext has access to beans in the parent one, but the parent cannot see the web one.

You can create your own custom scopes and they will mean what you want them to mean. An example say would be Thread scope, where beans get created per Thread. But you have to implement that work.

Prototype, is everytime you call getBean() you get a brand new instance.

I purposefully removed the need to think in terms of servlets because while two Spring scopes match in the web environment. The subject of Spring scopes is a different subject.

Hope that helps

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet scopes vs. bean scopes in Spring