Action beans should/must be "prototype" scope ?
Cantor, Scott
cantor.2 at osu.edu
Wed Feb 5 22:16:45 EST 2014
On 2/5/14, 10:05 PM, "Brent Putman" <putmanb at georgetown.edu> wrote:
>
>I didn't think there was anything like a default scope for a beans file.
There's not.
>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:
No, I think it's just saying that scope can be overridden by the child. I
think you can declare it on the parent. But having said that, remembering
to define scope for every Action is not much different than remembering to
inherit them all from a parent, and it's more verbose, so I didn't suggest
it.
>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.
Also for maintenance. If I want to rework the internals of an Action, I'd
rather know that all actions are declared prototype.
>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).
We've avoided that I think. Unless we can do this with a post-processor, I
don't think there's much we can do.
>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.
No, but I haven't really looked out for them.
-- Scott
More information about the dev
mailing list