Ian Roberts wrote:
http://johnheintz.blogspot.com/2007/11/using-lazy-proxy-to-avoid-spring.html

The LazyProxyFactoryBean shown in this post basically allows you to wrap up another Spring bean with a proxy that shows the same interface, but delays asking for the "real" bean until the first method call. Using this in combination with the lazy-init=true trick above should do what you're after.

In fact, it turns out Spring has built-in support for exactly this using the AOP ProxyFactoryBean:

<bean id="accountProxyFactory"
      class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"
      lazy-init="true">
  <property name="serviceClass" value="my.web.service.AccountService"/>
  <property name="address" value="${account.service}"/>
</bean>

<bean id="realAccountService" class="my.web.service.AccountService"
      factory-bean="accountProxyFactory" factory-method="create"
      lazy-init="true"/>

<bean id="accountService"
      class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="targetSource">
    <bean class="org.springframework.aop.target.LazyInitTargetSource">
      <property name="targetBeanName">
        <idref local="realAccountService"/>
      </property>
    </bean>
  </property>
  <property name="proxyInterfaces"
            value="my.web.service.AccountService" />
</bean>

Ian

--
Ian Roberts               | Department of Computer Science
[EMAIL PROTECTED]  | University of Sheffield, UK

Reply via email to