title: Returning null from factory method in Spring
body: <p>In my spring configuration file, I have declared one bean which is instantiated via a static factory method. The factory method invokes some remote services. The factory method returns null incase it is not able to access the remote service.</p>
  
  <p>My problem everything goes wrong when the factory method returns null. and The spring initialization fails.</p>
  
  <p>I really want to set the bean to null, if the factory method is not able to invoke the remote service.</p>
  
  <p>Part of my config file is as follows :</p>
  
  <pre><code>&lt;bean id="Helper" class="com.test.Helper"&gt;
     &lt;constructor-arg ref="myBean" /&gt;
  &lt;/bean&gt;
  &lt;bean id="myBean" class="com.test.Factory" factory-method="getBean" /&gt;
  </code></pre>
  
  <p>the getBean() method is as follows:</p>
  
  <pre><code>Factory {
        public static Bean getBean() throws Exception{
  
               try {
                  //Invokes some Remote Services and does some processing
                  ....
                  ....
                  //returns bean object
              }catch(Exception e) {
                  return null;
              }    
        }
  
    }
  </code></pre>
  
  <p>Please help me how can I solve this.</p>