|
From: Rod J. <rod...@in...> - 2003-11-20 19:13:44
|
My original intention was that FactoryBeans must be singletons and that
attempts to define them as prototypes should throw a
BeanDefinitionStoreException. One level of indirection should be enough.
Regards,
Rod
----- Original Message -----
From: "roger holbrook" <apo...@sn...>
To: <spr...@li...>
Sent: Thursday, November 20, 2003 6:28 PM
Subject: [Springframework-developer] Re: Intercepting a Prototype Bean
> Rod
>
> I think this is a probably bug in AbstractBeanFactory - currently any
> getBean() for a FactoryBean that was defined with a bean attribute of
> singleton="false", will always return the FactoryBean instance, rather
than
> a Proxy instance. This happens because createBean() does not do any
factory
> dereferencing.
>
> One fix would just be to trap the combination when the beans are being
> defined.
>
> Even if createBean() were actually handling the dereferencing correctly,
> I think there would still be a problem on a normal sequence of getBean()
> calls - since each call would generate a new FactoryBean instance and a
new
> Proxy instance, but the application code would only ever see a reference
to
> the latter. Application code would only be able collect references to the
> FactoryBean themselves by explicitly calling getBean("&name"), and then
> using these to generate Proxy instances.
>
> A bit confusing really
>
> Roger
>
>
> "Rod Johnson" <rod...@in...> wrote in message
> news:06aa01c3af8b$d4467c90$e900a8c0@chopin...
> > Mark,
> >
> > > Is it possible to apply an interceptor to a prototype bean?
> > Yes.
> >
> > > The prototype is stateful - i.e one per user
> > Yes, Spring supports mixins, ie one interceptor per mixin instance.
> >
> > > I have defined the following in applicationContext.xml
> > >
> > >
> > > <bean id="TestTarget" class="test.MyTarget" singleton="false">
> > > </bean>
> > >
> > >
> > > <bean id="TestInterceptor"
> > >
> >
>
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBe
> > > an" singleton="false">
> > > <property name="transactionManager"><ref
> > > local="transactionManager"/></property>
> > >
> > > <property name="target"><ref local="TestTarget"/></property>
> > >
> > >
> > > <property name="transactionAttributes">
> > > <props>
> > > <prop key="foo">PROPAGATION_REQUIRED</prop>
> > > </props>
> > > </property>
> > > </bean>
> > >
> > >
> > >
> > > When I invoke the method foo I get a ClassCastException
> >
> > Not sure why this is happening but you may need to create the
interceptor
> > chain manually to use a prototype, as TransactionProxyFactoryBean
propably
> > assumes it's dealing with a singleton. So you need to create a chain
that
> > includes:
> > - the name of your prototype
> > - the interceptor names, which may be singletons or prototypes as you
> > require. Use a prototype for mixin support.
> >
> > The following example comes from the test suite, with minor changes to
> make
> > it more obvious:
> >
> >
> > <bean id="prototypeTarget"
> > class="org.springframework.aop.interceptor.SideEffectBean"
> > singleton="false">
> > <property name="count"><value>10</value></property>
> > </bean>
> >
> > <!-- This can be a singleton or a prototype (for mixin behaviour) -->
> > <bean id="debugInterceptor"
> > class="org.springframework.aop.interceptor.DebugInterceptor">
> > </bean>
> >
> >
> > <bean id="prototype"
> > class="org.springframework.aop.framework.ProxyFactoryBean">
> > <!-- will automatically create invoker interceptor for the
prototype -->
> > <property
> >
>
name="interceptorNames"><value>debugInterceptor,prototypeTarget</value></pro
> > perty>
> >
> > <!-- Note this -->
> > <property name="singleton"><value>false</value></property>
> > </bean>
> >
> > There is a bug in M2 to do with prototype AOP handling, which is fixed
in
> > the forthcoming M3. However I don't think it should affect you in such a
> > simple usage.
> >
> >
> > Regards,
> > Rod
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: SF.net Giveback Program.
> > Does SourceForge.net help you be more productive? Does it
> > help you create better code? SHARE THE LOVE, and help us help
> > YOU! Click Here: http://sourceforge.net/donate/
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|