Announcement Announcement Module
Collapse
No announcement yet.
Return a new instance from ProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Return a new instance from ProxyFactoryBean

    Hi,

    I m new to springframework. I just wanna to implement the springframework at my business layer tier. I use the ProxyFactoryBean to lookup my BO instance from the application context in my web tier. But the ProxyFactoryBean always return the same BO instance, instead of the new BO instance. In fact, i had set the BOImpl bean to singleton="false". How do i return a new instance from the ProxyFactoryBean ? Any advise ? Thanks.

    The bean config as below:
    <bean id="boInterface" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces">
    <value>com.work.BOInterface</value>
    </property>
    <property name="target">
    <ref local="boImpl"/>
    </property>
    <property name="singleton"><value>false</value></property>
    </bean>

    <bean id="boImpl" class="com.work.BOImpl" singleton="false">
    <property name="persistenceManagerFactory">
    <ref bean="pmf"/>
    </property>
    </bean>

    Regards,
    Kuahkg

  • #2
    Do you not need to identify the ProxyFactoryBean as "singleton=false" *on the bean* declaration?

    Comment


    • #3
      Originally posted by yatesco
      Do you not need to identify the ProxyFactoryBean as "singleton=false" *on the bean* declaration?
      Nope.. it might not work as well.

      Comment


      • #4
        Did you already solve this problem? I also want to get a singleton object from a transaction factory...

        Comment


        • #5
          Maybe I don't understand, but why are you using a ProxyFactoryBean? Why not just:

          <bean id="boInterface" class="com.work.BOImpl" singleton="false">
          <property name="persistenceManagerFactory">
          <ref bean="pmf"/>
          </property>
          </bean>

          Then you can access it:

          BOInterface bo = ( BOInterface )applicationContext.getBean( "boInterface" );

          This should return a new instance each time. Or is your example not fully defined? Sorry if I misunderstand.

          Comment


          • #6
            try

            <bean id="boInterface" class="org.springframework.aop.framework.ProxyFact oryBean">
            <property name="proxyInterfaces">
            <value>com.work.BOInterface</value>
            </property>
            <property name="targetName">
            <value>boImpl</value>
            </property>
            <property name="singleton"><value>false</value></property>
            </bean>

            have a try.......

            Comment


            • #7
              Yes, you can't use a ref, you need to specify the bean name of the target. You can actually include the target name at the conclusion of the interceptorNames, in CSV format or a list.

              Comment

              Working...
              X