Cratylus
Cratylus

Reputation: 54074

Utilize session bean or store a custom object in session?

I am confused on the following:
I can store a custom object for later usage inside the httpsession object.
Later usage I mean for usage by various servlets/filters during the same session.

Or I could use Spring session bean.

I was wondering (setting other parameters aside) would I gain any advantage by using the Spring's session bean?

I am failing to see some importance difference.

Upvotes: 2

Views: 359

Answers (2)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340733

You can directly inject session-scoped Spring bean into other beans, even singletons in any application layer (services, or even DAOs).

Spring does the magic of wrapping the bean and always routing to appropriate object. Without session-scoped beans you are doomed to interact with HTTP session directly. This also makes testing a little bit harder.

Upvotes: 1

Bozho
Bozho

Reputation: 597106

You can inject other beans in the session bean.

If it is a simple value-holder, it doesn't make much difference. But if you want to operate on those values (by invoking services), then having it as spring bean is beneficial.

Another plus is the fact that your code is not dependent on the servlet API. And it is easier to test.

Upvotes: 2

Related Questions