Announcement Announcement Module
Collapse
No announcement yet.
Non-singleton TransactionProxyFactoryBean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Non-singleton TransactionProxyFactoryBean?

    Hi,
    I want to use delartive transaction, so I declard my service as
    Code:
    	<bean id="reportFacadeImpl" class="model.logic.impl.ReportFacadeImpl" singleton="false"/>
    
    	<bean id="reportFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<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
    Code:
    appContext.getBean&#40;"reportFacade"&#41;
    I alwas get the same instance.

    Colud I get differnt instances from TransactionProxyFactoryBean?
    Thanks!

  • #2
    Also set the singleton flag to false for the ProxyFactoryBean. That should do the trick.

    regards,
    Alef Arendsen

    Comment


    • #3
      Hi,
      When I set the singleton flag to false as following
      Code:
      	<bean id="reportFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" singleton="false">
      		<property name="target"><ref local="reportFacadeImpl"/></property>
      ...skip...
      </bean>
      Spring will throw the exception ....

      Code:
      Caused by&#58; org.springframework.beans.factory.BeanDefinitionStoreException&#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.BeanDefinitionValidationException&#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!

      Comment


      • #4
        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.
        HTH

        Comment


        • #5
          I think you can by using a PrototypeTargetSource...

          http://www.springframework.org/docs/...p-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

          Comment


          • #6
            Thank irbouho, it worked!

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

            Code:
            org.springframework.beans.factory.BeanCreationException&#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.BeanDefinitionStoreException&#58; Cannot use PrototypeBasedTargetSource against a singleton bean&#58; instances would not be independent

            Comment


            • #7
              Can you please post your working example?

              Can you please post your working example?

              Thanks

              Comment


              • #8
                it is only used for singleton

                TransactionProxyFactoryBean is just used for singleton. Read the doc about it.

                If you want prototype, use ProxyFactoryBean.

                Comment


                • #9
                  Prototype ProxyFactoryBean throwing BeanDefinitionValidationException

                  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:
                  Code:
                  org.springframework.beans.factory.support.BeanDefinitionValidationException: FactoryBean must be defined as singleton - FactoryBeans themselves are not allowed to be prototypes
                  Here is the concerned section of my applicationContext.xml file:
                  Code:
                         <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.VisualizationServiceImpl">
                                  <property name="popTmplDao"><ref bean="popTmplDao"/></property>
                              </bean>
                          </property>
                          <property name="proxyInterfaces">
                              <value>com.mvn.contenttools.service.visualization.VisualizationService</value>
                          </property>
                          <property name="interceptorNames">
                              <list>
                                  <value>serviceTransactionInterceptor</value>
                                  <value>hibernateInterceptor</value>
                              </list>
                          </property>
                      </bean>
                  Any clue? Thanks in advance.

                  Comment


                  • #10
                    Can't use 'target' variable in ProxyFactoryBean for singletons

                    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/arc...p/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.

                    Comment

                    Working...
                    X