PDA

View Full Version : Non-singleton TransactionProxyFactoryBean?



leonchen
Mar 13th, 2005, 09:24 AM
Hi,
I want to use delartive transaction, so I declard my service as


<bean id="reportFacadeImpl" class="model.logic.impl.ReportFacadeImpl" singleton="false"/>

<bean id="reportFacade" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="target"><ref local="reportFacadeImpl"/></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>



If I try to


appContext.getBean&#40;"reportFacade"&#41;


I alwas get the same instance.

Colud I get differnt instances from TransactionProxyFactoryBean?
Thanks!

Alef Arendsen
Mar 13th, 2005, 10:21 AM
Also set the singleton flag to false for the ProxyFactoryBean. That should do the trick.

regards,
Alef Arendsen

leonchen
Mar 13th, 2005, 08:48 PM
Hi,
When I set the singleton flag to false as following


<bean id="reportFacade" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean" singleton="false">
<property name="target"><ref local="reportFacadeImpl"/></property>
...skip...
</bean>


Spring will throw the exception ....



Caused by&#58; org.springframework.beans.factory.BeanDefinitionSt oreException&#58; Error registering bean with name 'reportFacade' defined in class path resource &#91;LogicContext.xml&#93;&#58; Validation of bean definition with name failed; nested exception is org.springframework.beans.factory.support.BeanDefi nitionValidationException&#58; FactoryBean must be defined as singleton - FactoryBeans themselves are not allowed to be prototypes


It looks like "FactoryBean must be defined as singleton " ...

Thrank for any futher recommendation!

irbouho
Mar 13th, 2005, 09:00 PM
leonchen,
TransactionProxyFactoryBean may be used with stateless services. For protoypes, you may use a AutoProxyCreator. For more informations, please take a look at Declarative transaction with BeanNameAutoProxyCreator (http://forum.springframework.org/viewtopic.php?t=809).
HTH

erikw
Mar 15th, 2005, 04:16 PM
I think you can by using a PrototypeTargetSource...

http://www.springframework.org/docs/reference/aop.html#aop-ts-prototype

In which case the "target" property of your TransactionProxyFactoryBean (reportFacade) would point to this new PrototypeTargetSource bean, and this new bean would point to your reportFacadeImpl bean.

I'm not entirely sure, so could you let me know if this worked?

Regards,
Erik

leonchen
Mar 16th, 2005, 08:24 PM
Thank irbouho, it worked!

Thank erikw, but unfortunately, it will throw exception, as following



org.springframework.beans.factory.BeanCreationExce ption&#58; Error creating bean with name 'reportFacade' defined in class path resource &#91;LogicContext.xml&#93;&#58; Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException&#58; Cannot use PrototypeBasedTargetSource against a singleton bean&#58; instances would not be independent

dgefter
Jan 4th, 2006, 06:29 PM
Can you please post your working example?

Thanks

tester5
Jan 6th, 2006, 01:35 AM
TransactionProxyFactoryBean is just used for singleton. Read the doc about it.

If you want prototype, use ProxyFactoryBean.

Jeffer
Mar 2nd, 2006, 05:26 PM
Hi,

Pretty new to Spring here. I'm using the AndroMDA Spring cartridge and I'm trying to set a service as a prototype but I'm getting this error:

org.springframework.beans.factory.support.BeanDefi nitionValidationException: FactoryBean must be defined as singleton - FactoryBeans themselves are not allowed to be prototypes


Here is the concerned section of my applicationContext.xml file:


<bean id="visualizationService" class="org.springframework.aop.framework.ProxyFactoryBean" singleton="false" init-method="initialize" destroy-method="destroy">
<property name="target">
<bean class="com.mvn.contenttools.service.visualization.Visuali zationServiceImpl">
<property name="popTmplDao"><ref bean="popTmplDao"/></property>
</bean>
</property>
<property name="proxyInterfaces">
<value>com.mvn.contenttools.service.visualization.Visuali zationService</value>
</property>
<property name="interceptorNames">
<list>
<value>serviceTransactionInterceptor</value>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>


Any clue? Thanks in advance.

cssathya
Mar 16th, 2006, 04:43 PM
Hi Jeffer,

You cannot use the 'target' property. You must use the 'targetName' property instead. Here's a thread that explains the reasons.

http://forum.springframework.org/archive/index.php/t-10632.html

If the link doesn't work, try the Google cache.

Also, irbrouho's suggestion above works in a similar way. I don't see any difference between the two.

Hope this helps.

Sathya.