This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Servlet scopes vs. bean scopes in Spring

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic