Announcement Announcement Module
Collapse
No announcement yet.
Problem specifying a bean as a prototype (non-singleton) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem specifying a bean as a prototype (non-singleton)

    I am using Spring 1.2.2 and AOP for the first time, and I am having a problem declaring one of my beans as a prototype. That is, every time I call XmlBeanFactory.getBean("WorkSpaceBase"), it returns the same instance of the target object.

    My configuration XML is below - it is very simple; similar to the AOP examples in books and documentation.

    I have an idea where the problem might be - I have declared "WorkSpaceBaseTarget" as singleton="false". When I try to do the same with "WorkSpaceBase" itself, I get an error saying I can't do that with a factory bean. How should I be doing this?

    Thanks!

    Barry Hart

    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>

    <!-- Declares the ultimate target class -->
    <bean id="WorkSpaceBaseTarget"
    class="com.blox.data.WorkSpaceBase"
    singleton="false"/>

    <!-- Declares a class that intercepts WorkSpaceBase methods -->
    <bean id="WorkSpaceBaseAutoTransactionAdvice"
    class="com.blox.data.WorkSpaceBaseAutoTransactionA dvice"/>

    <!-- Filters which methods are intercepted -->
    <bean id="transactionalMethodAdvisor"
    class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedName">
    <value>*</value>
    </property>
    <property name="advice">
    <ref bean="WorkSpaceBaseAutoTransactionAdvice"/>
    </property>
    </bean>

    <!-- Declares a bean where WorkSpaceBaseAutoTransactionAdvice intercepts WorkSpaceBase methods -->
    <bean id="WorkSpaceBase"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.blox.data.WorkSpace</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>WorkSpaceBaseAutoTransactionAdvice</value>
    </list>
    </property>
    <property name="target">
    <ref local="WorkSpaceBaseTarget"/>
    </property>
    </bean>
    </beans>

  • #2
    I also tried adding the "singleton" property to the ProxyFactoryBean. This didn't work, either - still only one instance of my object is created.

    <!-- Declares a bean where WorkSpaceBaseAutoTransactionAdvice intercepts WorkSpaceBase methods -->
    <bean id="WorkSpaceBase"
    class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.blox.data.WorkSpace</value>
    </property>
    <property name="singleton">
    <value>false</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>WorkSpaceBaseAutoTransactionAdvice</value>
    </list>
    </property>
    <property name="target">
    <ref local="WorkSpaceBaseTarget"/>
    </property>
    </bean>

    Comment

    Working...
    X