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

  • Circular references with ProxyFactoryBean

    I'm about at my wit's end. Hopefully somebody can help me out here.

    I'm doing the typical: (forgive the crudeness of the xml, I don't have the code in front of me, but this is the idea)

    <bean id="abstractProxy" class="ProxyFactoryBean" abstract="true">
    <property name="interceptors">
    <list>
    <value>myInterceptor</value>
    <list>
    </property>
    </bean>

    <bean id="abstractBean" class="BaseBean" abstract="true"/>

    <bean id="myProxiedBean" parent="abstractProxy">
    <property name="proxiedInterfaces">
    <list>
    <value>InterfaceForProxiedBean</value>
    </list>
    </property>
    <property name="target">
    <bean parent="abstractBean">
    ...
    ...
    </bean>
    </property>
    </bean>

    <bean id="mySecondProxiedBean" parent="abstractProxy">
    <property name="proxiedInterfaces">
    <list>
    <value>InterfaceForSecondProxiedBean</value>
    </list>
    </property>
    <property name="target">
    <bean parent="abstractBean">
    ...
    ...
    </bean>
    </property>
    </bean>

    <bean id ="myThirdProxyBean>
    ...
    ...
    </bean>
    fourth,
    fifth,
    sixth, etc.

    <bean id="myManager" class="MyManager">
    <property name="bean1" value="myProxiedBean"/>
    <property name="bean2" value="mySecondProxiedBean"/>
    </bean>
    (bean1 and bean2 are of type InterfaceForProxiedBean and INterfaceForSecondProxiedBean, respectively)

    <bean id="myManager2" class="MyManager2">
    <property name="bean1" value="myProxiedBean"/>
    <property name="bean2" value="mySecondProxiedBean"/>
    </bean>
    (bean1 and bean2 are of type InterfaceForProxiedBean and
    INterfaceForSecondProxiedBean, respectively)


    And last of all:

    <bean id="proxyCreator" class="BeanNameAutoProxyCreator">
    <property name="*Manager" />
    <property name="interceptorNames">
    <list>
    <value>someInterceptor</value>
    </list>
    </property>
    </bean>


    This works nearly ALL the time, but sometimes it fails.

    I get INTERMITTENT and UNPREDICTABLE circular reference errors and BeanNotCreated Exceptions.

    When I remove the BeanNameAutoProxyCreator everything works fine. Obviously that's where the circular problem is appearing. Does this qualify as being circular?

    Is there a workaround for this? I've wanted to use an aop:config block but I think that the aop:config block only allows introductions on an object when the pointcut has been satisfied. I need to proxy certain interfaces earlier than that.

    Does anybody know how to handle this?

    Can it be handled?

    The fact that it works intermittently tells me that this approach is at least somewhat correct. Is this a bug or is this just bad practice on my part?

  • #2
    I've never got such an error.

    Anyway, you can completely exclude 'BeanNameAutoProxyCreator' from the processing by using AspectJ weaving.

    P.S. your vision about <aop:config> is incorrect - it allows to do the same as spring1 aop but in more convenient and less verbose manner. For example 'BeanNameAutoProxyCreator' is replaced by 'bean' pointcut designator.

    Comment


    • #3
      Per Spring's Documentation:

      Introductions (known as inter-type declarations in AspectJ) enable an aspect to declare that advised objects implement a given interface, and to provide an implementation of that interface on behalf of those objects.

      That is NOT what I want done. I want to proxy a specific interface to an object no matter what. The object may never be advised, but it has an interface proxied into it anyway.

      Comment

      Working...
      X