Action beans should/must be "prototype" scope ?
Brent Putman
putmanb at georgetown.edu
Wed Feb 5 22:05:03 EST 2014
On 2/4/14 7:24 PM, Cantor, Scott wrote:
> I thought you could set it on the beans element, maybe not.
I didn't think there was anything like a default scope for a beans file.
Related, I had way back thought it might make sense to define abstract
bean definitions for things that shared common properties or had other
common characteristics (like 'scope'). AFAIK, even there, the 'scope'
property of a BeanDefinition is one of the things that is *not*
inherited, so you have to define it on every leaf bean individually. At
least that's what I understand from the docs (5.7 Bean definition
inheritance), where it says:
> The remaining settings are /always/ taken from the child definition:
> /depends on/, /autowire mode/, /dependency check/, /singleton/,
> /scope/, /lazy init/.
So sounds like no help via this approach either.
> If not, I
> guess we should do something, but there are likely going to be beans in
> the flow bean files that would be singleton, so I don't know how we'd
> limit the post-processor.
I don't know how we would either, other than by reflection or instanceof
on some interface. Would have to make sure that the assumptions there
always held, or were define with enough specificity.
On the original question: the purist in me says that beans in general
should be marked accordingly to what they actually are and need, i.e. we
shouldn't apply 'prototype' everywhere just to avoid mistakes. But I do
recognize the drastic consequences of a bean failing to be marked as
prototype where it should be.
In general, though, aren't most or all of our bean definition files
likely to have a mixture of scopes? So really, unless we can do
something global or with a bean definition post processor, we pretty
much just have to make sure to not make mistakes. (Which by the way,
includes injecting a prototype or other non-singleton scoped bean into a
singleton without doing the appropriate additional stuff).
On a related note: have we had any use cases for scopes other than
'singleton' and 'prototype', like 'request' or 'session'? Just
wondering. For some other work I have recently been using both
'session' scoped beans and the <aop:scoped-proxy> stuff to inject them
into other 'singleton' beans, and it works nicely.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20140205/9d474737/attachment.html
More information about the dev
mailing list