Spring IoC, WebFlow and scopes
Brent Putman
putmanb at georgetown.edu
Mon Jun 24 21:16:08 EDT 2013
I ran across some info somewhat related to what came up on the call on
Friday, namely the issue of Spring behavior around destruction callbacks
and collaborating beans. I was playing around with making the message
encoder beans live in different non-singleton scopes, in case we needed
to use them in more than one component, and saw some logging that made
me go do some research.
First, it's reasonably clear that destruction callbacks are done in the
reverse order from the initialization callbacks. That's what one would
expect. However, this is only true for singleton beans. They say in
the manual section on depends-on:
> The depends-on attribute in the bean definition can specify both an
> initialization time dependency and, in the case of singleton beans
> only, a corresponding destroy time dependency. Dependent beans that
> define a depends-on relationship with a given bean are destroyed
> first, prior to the given bean itself being destroyed. Thus depends-on
> can also control shutdown order.
I would assume this behavior also applies with implicit dependencies (in
the same way as it does for init callbacks). But if not then I suppose
worst case one can just declare an explicit depends-on.
The fact that there doesn't appear to be any guaranteed destruction
callback ordering for non-singleton beans is potentially concerning.
More concerning though: it appears WebFlow does not support destruction
callbacks for beans registered in its custom scopes, period. I think
we'd be mostly interested in 'flow' and 'conversation' scopes, but for
the record the limitation also applies to their 'flash' and 'view'
scopes. I looked at the code and they just don't support those at all.
They do log a warning to tell you.
I don't know how much that practically affects us yet, but the lack of
WebFlow destruction callbacks was a bit surprising and disappointing.
--Brent
More information about the dev
mailing list