Results 1 to 3 of 3

Thread: ProxyFactoryBean proxying singleton

  1. #1
    Join Date
    Nov 2004
    Posts
    5

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    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

  3. #3
    Join Date
    Nov 2004
    Posts
    5

    Default Fixed now!

    proxyInterfaces solved the problem. Thanks!

Similar Threads

  1. Is a 'singleton' flow a bad idea?
    By akw in forum Web Flow
    Replies: 4
    Last Post: Oct 6th, 2005, 01:16 AM
  2. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 6
    Last Post: May 25th, 2005, 01:56 AM
  5. DefaultAdvisorAutoProxyCreator skipping beans
    By youngm in forum Container
    Replies: 6
    Last Post: Apr 12th, 2005, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •