The moose likes Spring and the fly likes spring scopes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring scopes" Watch "spring scopes" New topic

spring scopes

G.Sathish kumar
Ranch Hand

Joined: Jul 27, 2009
Posts: 84
Types of Scopes
The five different types of scopes supported in the Spring Framework are as follows :

Global Session

i am not able to find the use of Session and globale session. i am creating the domain object for each user when successfull login so i feel to use the session spring scope like to place my main proxy factory bean which contain all module model implementation beans to spring bean session scope.

so please update me if am wrong?

Sathish kumar
caradk milk

Joined: Nov 15, 2009
Posts: 3
We implemented our own custom Spring scope. A lot of our code works at a relatively low level, close to the database, and we maintain a conceptual level on top of that with its own object model of data sources, links, attributes etc.

Anyway, a lot of beans require a so-called StorageDictionary (an encapsulation of this object graph) to do their work. When we make non-trivial changes to the object graph, the dictionary sometimes needs to be blown away and recreated. Consequently, we implemented a custom scope for objects that were dictionary scoped, and part of the invalidation of a given dictionary involves clearing this custom scope. This lets Spring handle a nice form of automatic caching for these objects. You get the same object back every time up until the dictionary is invalidated, at which point you get a new object.

This helps not only with consistency but also allows the objects themselves to cache references to entities within the dictionary, safe within the knowledge that the cache will be valid for as long as they themselves are retrievable by Spring. This in turn lets us build these as immutable objects (so long as they can be wired via constructor injection), which is a very good thing to do anyway wherever possible.

This technique won't work everywhere and does depend heavily on the characteristics of the software (e.g. if the dictionary was modified regularly this would be horribly inefficient, and if it was updated never this would be unnecessary and slightly less efficient than direct access). However, it has definitely helped us pass off this management of lifecycle to Spring in a way that is conceptually straightforward and in my opinion quite elegant.
I agree. Here's the link:
subject: spring scopes
It's not a secret anymore!