Action beans should/must be "prototype" scope ?
Tom Zeller
tzeller at dragonacea.biz
Tue Feb 4 19:19:38 EST 2014
>>Should or must Action beans be defined with scope="prototype" ?
>
> It depends on the bean, but the only cost of using prototype for all of
> them is performance, and that isn't really intended to be a factor. To
> avoid nasty errors, we really should use prototype.
Right.
If we use private fields which are set in doPreExecute() :
public class SomeAction ....
private SomeObject someObject;
doPreExecute() { ...
someObject = ...
doExecute() { ...
someObject.someMethod() ...
then the scope must be prototype. However, the scope is set in a bean
definition file "far away" from the Java code, which seems potentially
problematic. If there was a @Scope annotation, I might suggest it. Am
I making sense ?
>>Do we want to consider changing the default from "singleton" to
>>"prototype" ?
>
> That's ok if it affects just those files, which I think it does.
I think changing the default scope needs to be done in a BeanPostProcessor.
More information about the dev
mailing list