Announcement Announcement Module
Collapse
No announcement yet.
ProxyFactoryBean proxying singleton Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ProxyFactoryBean proxying singleton

    I have a ProxyFactoryBean proxing a bean which is created using a MethodInvokingFactoryBean.

    MethodInvokingFactoryBean works fine. However, when I wrap it in a ProxyFactoryBean the latter creates a NEW instance (I see the no-arg constructor runs) of the bean originally returned by the MethodInvokingFactoryBean, it does not wrap at all this original. Moreover, ProxyFactoryBean decides to go to the constructor directly, bypassing our factory.

    Why isn't ProxyFactoryBean proxying the original bean returned by MethodInvokingFactoryBean?!

    Bart

    <bean id="simpleApplicationServiceDelegateFactory" class="com.vangenechten.common.j2ee.SimpleApplicat ionServiceDelegateFactoryFactoryBean">
    </bean>

    <bean id="mdasd-naked" class="org.springframework.beans.factory.config.Me thodInvokingFactoryBean" singleton="true" >
    <property name="targetObject">
    <ref local="simpleApplicationServiceDelegateFactory"/>
    </property>
    <property name="targetMethod">
    <value>getApplicationServiceDelegate</value>
    </property>
    <property name="arguments">
    <list>
    <value>com.vangenechten.masterdata.client.masterda ta.MasterDataApplicationServiceDelegate</value>
    </list>
    </property>
    </bean>

    <bean id="mdasd" class="org.springframework.aop.framework.ProxyFact oryBean" singleton="true" >
    <property name="target">
    <ref local="mdasd-naked"/>
    </property>
    <property name="interceptorNames">
    <list>
    <value>commitInterceptor</value>
    <value>commitThrowsAdvice</value>
    </list>
    </property>
    </bean>

  • #2
    Hi Bart,

    The problem is that you're not specifying a proxy interface for your ProxyFactoryBean, so you force it to create a CGLIB proxy (assuming that your target object as created by MethodInvokingFactoryBean does not implement any interfaces).

    A CGLIB proxy is technically an instance of a subclass of your target class, so what you will see is in fact another call to the constructor of your target class. That's the way CGLIB works; this can indeed incur unintuitive effects, unfortunately.

    I recommend to let your target object implement a business interface and specify a corresponding "proxyInterfaces" value on your ProxyFactoryBean definition, to enforce a JDK proxy rather than a CGLIB proxy.

    Juergen

    Comment


    • #3
      Fixed now!

      proxyInterfaces solved the problem. Thanks!

      Comment

      Working...
      X