title: Spring 3: Postpone bean instanciation
body: <p>I have a bean that uses a JNDI Connection Factory like this:</p>
  
  <pre><code>&lt;bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiTemplate" ref="jndiTemplate"/&gt;
      &lt;property name="jndiName" value="SOME_NAME"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"&gt;
      &lt;property name="environment"&gt;
          &lt;props&gt;
              &lt;prop key="java.naming.factory.initial"&gt;org.ow2.carol.jndi.spi.MultiOrbInitialContextFactory&lt;/prop&gt;
              &lt;prop key="java.naming.provider.url"&gt;rmi://some_remote_host:1091&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The fact is that this connectionFactory tries to connect to the remote host <strong>as soon as the context is loaded</strong>. The problem is that the remote service is supposed to start after the context is loaded, the context fails to load, and the application fails to deploy. Would it be possible to postpone the connection of the factory to the moment when the connection is really needed?</p>
  
  <p>In other words, the connection to the connection factory is eager, and I would like it to be lazy. Is there a way to achieve this appart from subclassing the Factory and hacking around?</p>