Spring IoC, WebFlow and scopes
Brent Putman
putmanb at georgetown.edu
Tue Jun 25 12:32:19 EDT 2013
On 6/25/13 12:08 PM, Cantor, Scott wrote:
> This is becase Spring doesn't support destruction callbacks for
> non-singletons at all, I think.
No, the standard Spring (non-WebFlow) 'request' and 'session' scopes do
support destruction callbacks. I tested the request one, it got called
when the request went out of scope. From looking at the code, I think
the session one would work the same way, although I couldn't devise any
immediate easy way to test it.
> My assumption is that the various plugins in the system in the resolver
> and filter are going to be singletons, but of course we decided other
> things wouldn't be.
Yeah, I thought most of the components will be singletons, so that's why
I'm not terribly concerned. And for prototypes we already knew that the
caller/recipient of the bean was responsible for destruction.
It might be that, for this reason, we might want to use 'request' scope
instead of 'prototype' for some of the per-use components (handlers,
actions) since those generally are invoked once per servlet request
anyway. If they have non-trivial destruction code then at least they'd
get called automatically. I haven't yet actually seen any examples
where this is critical though.
> I think that's just an extension of the general non-singleton rule?
No, the Scope interface (the thing that represents custom scopes)
actually has a method for registering destruction callbacks, so it's
clearly not a general limitation. That's how the 'request' and
'session' ones are implemented. For whatever reason, WebFlow just logs
a warning in their impls of those to say "We don't support this".
Probably it was difficult for them to hook those to be called in the
right place or something, or perhaps because of the ordering issue.
More information about the dev
mailing list