PDA

View Full Version : Scoped Beans



Thomas Ziem
Mar 11th, 2010, 03:08 AM
Hi together,

I'm using SI and need some help concerning scoped beans.

In my application I have beans which should be created and destroyed through a specific HTTP request. Each request that contains a unique conversation id should have access to these beans.
I can't use the session scope because there are several HTTP requests in different HTTP sessions.

How can I solve this?

Thanks in advance,
Thomas

Hetal B
Mar 11th, 2010, 03:16 AM
You can use the request scope

Thomas Ziem
Mar 11th, 2010, 03:30 AM
Hi,

As I undestand the request scope, the container will create a new bean for each HTTP request.
That is not what I want. I will use one bean across multiple HTTP requests from different HTTP sessions.

~Thomas

Hetal B
Mar 11th, 2010, 03:37 AM
So you need a single bean for various request /sessions? Which means you need a singleton scoped bean?

-Hetal

Thomas Ziem
Mar 11th, 2010, 03:44 AM
I need a bean instance for each HTTP request with a specific conversation id.
So the container should create a new instance if a HTTP request contains a new conversation id.

~Thomas

Hetal B
Mar 11th, 2010, 04:08 AM
Hi,

May be you can check the secttion 3.7.3 in ref doc http://static.springsource.org/spring/docs/2.5.x/reference/beans.html

-Hetal

iwein
Mar 16th, 2010, 01:24 AM
You could define a custom scope, but my first advice would be not to go there. Not that the api is not clean, but if you can avoid thinking about scopes you'll save yourself (and the maintenance programmers after you) a headache.

Thomas Ziem
Mar 16th, 2010, 02:26 AM
Hi Iwein,

the reason why I'm thinking about scopes is, that my service holds a state. The additional requirement is, that the service must handle multiple sessions (no HTTP sessions). Several HTTP clients can send requests to the service. The conversation id is part of the HTTP request. So I have to decide which request is connected with which service instance.

If I define a custom scope I don't know how to signal the end of the scope.

~Thomas