Announcement Announcement Module
No announcement yet.
Optional targetsource for a ProxyFactoryBean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:


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


    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,


    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):

      <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 index="1">
      <bean name="view" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="singleton"><value>false</value></property>
        <property name="defaultTargetSource">
        <property name="proxyInterfaces">
        <property name="interceptorNames">
    This is probably not very clear, so feel free to ask me to clarify. :wink:


  • #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.


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

      Thanks guys, that's awesome!