Action beans should/must be "prototype" scope ?

Tom Zeller tzeller at dragonacea.biz
Thu Feb 6 13:40:24 EST 2014


>>I was wondering whether we can protect against this?  Prototype-bean
>>actions
>>should never see a #preExecute after an #execute(), right?  So could we
>>set
>>a flag in execute and test it in #preExecute().  If we did this somewhere
>>deep in the class hierarchy we would get a lot of bang for our buck.
>
> That doesn't sound like a crazy idea.

Looks like we could annotate actions with @Scope and implement
ApplicationContextAware :

 @Scope(BeanDefinition.SCOPE_PROTOTYPE)
 public class SignAssertions ... implements ApplicationContextAware {

and check whether or not the bean is actually prototype or not :

  Scope scope = this.getClass().getAnnotation(Scope.class);
    if (scope != null) {
      if (BeanDefinition.SCOPE_PROTOTYPE.equals(scope.value())) {
        if (!appCtx.isPrototype(getId())) {
          log.error("app {}", appCtx.isPrototype(getId()));
          ...

but we also need to set the bean id as a property redundantly :

<bean
        id="SignAssertions"
        class="net.shibboleth.idp.saml.impl.profile.saml1.SignAssertions"
        scope="prototype"
        p:id="SignAssertions" />

and combine with some sort of isExecuted boolean flag, I guess.


More information about the dev mailing list