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

  • Optional targetsource for a ProxyFactoryBean

    Hi, I have a use case that I would like to implement but am at a loss as to how to do it.

    I have a set of objects which, depending on the business context, need to be wired with advice. However, the targetsource for the advice is not always another bean. That is, sometimes I instantiate the proxy like this:

    context.getBean("aBean");
    aBean.setTargetSource(object);
    ...

    And sometimes I just want to do this and have the context supply it's own targetSource like this:

    context.getBean("aBean");
    ...

    So, what I am trying to do is avoid setting a targetSource in the config and then resetting it with the call to setTargetSource. So is there a way (or how do you think I could build a way) so ProxyFactoryBean gets it's targetSource from a bean in the context when it's needed and not supplied by a manual call to setTargetSource?

    So then,

    context.getBean("aBean");

    would always return a proxy without a target source, but as soon as I tried to invoke a method on the proxy, if the targetsSource hasn't yet been assiged, it has a "defaultTargetSource" reference that it can then resolve and set the resulting bean as the targetSource. Something like (note the "defaultTargetSource" property):

    Code:
      <bean "viewDomain" class="com.domain.ViewImpl" singleton="false" />
    
      <bean name="process1ViewAdvisor" class="com.core.ExtensionAdvisor" singleton="false">
        <constructor-arg index="0">
          <bean class="com.process1.ViewAdvisorImpl" singleton="false" />
          </constructor-arg>
        <constructor-arg index="1">
          <value>com.process1.ViewAdvisor</value>
        </constructor-arg>
      </bean>
    
      <bean name="view" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="singleton"><value>false</value></property>
        <property name="defaultTargetSource">
          <value>viewDomain</value>
        </property>
        <property name="proxyInterfaces">
          <value>com.domain.View,com.process1.View</value>
        </property>
        <property name="interceptorNames">
          <list>
            <value>process1ViewAdvisor</value>
          </list>
        </property>
      </bean>
    This is probably not very clear, so feel free to ask me to clarify. :wink:

    Cheers
    Steve

  • #2
    I am guessing that no one else has this need, or bumped their head and hasn't solved it. I'll trudge along and hopefully will be able to work something out.

    Comment


    • #3
      Hey, I just looked at the 1.2 announcement and I think LazyInitTargetSource does just what I need!

      Thanks guys, that's awesome!

      Comment

      Working...
      X