title: Spring bean injection throwing null pointer exception
body: <p>I'm trying to inject beanB into beanA, but for some reason, spring injection isn't working. When I try to use beanA in beanB, I'm getting null pointer exception.</p>
  
  <p>Here is my configuration...</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/spring/application-context.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>application-context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans
      xmlns="http://www.springframework.org/schema/beans" .........&gt;
  
      &lt;import resource="dao-beans.xml"/&gt;
      &lt;import resource="service-beans.xml"/&gt;
      ...................
      ...................
  &lt;/beans&gt;
  </code></pre>
  
  <p>service-beans.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans
      xmlns="http://www.springframework.org/schema/beans".........&gt;   
  
      &lt;bean id="serviceBeanA" class="com.test.ServiceBeanAImpl"/&gt;
      &lt;bean id="serviceBeanB" class="com.my.kodak.ServiceBeanBImpl"&gt;
          &lt;property name="serviceBeanA" ref="serviceBeanA"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>ServiceBeanBImpl.java</p>
  
  <pre><code>public class ServiceBeanBImpl{
  
      private ServiceBeanAImpl serviceBeanA;
  
      private String a;
  
      private String b;
  
      public ServiceBeanBImpl(){
          initializeBeanB();
      }
  
      initializeBeanB(){
          a = serviceBeanA.getA(); /// this is the line that throws Null pointer exception
          b = serviceBeanA.getB();
      }
  
      public String getServiceBeanA(){
          return this.serviceBeanA;
      }
  
      public String setServiceBeanA(ServiceBeanAImpl serviceBeanA){
          this.serviceBeanA = serviceBeanA;
      }
  
  }
  </code></pre>
  
  <p>When spring tries to initialize ServiceBeanBImpl, it is failing on the call to serviceBeanA. I've set a debug point on setServiceBeanA() method and it never gets called. I've also tried different ref strategies, but none of them worked..</p>
  
  <pre><code>&lt;bean id="serviceBeanB" class="com.my.kodak.ServiceBeanBImpl"&gt;
      &lt;property name="serviceBeanA"&gt;
           &lt;ref bean="serviceBeanA"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="serviceBeanB" class="com.my.kodak.ServiceBeanBImpl"&gt;
      &lt;property name="serviceBeanA"&gt;
           &lt;ref local="serviceBeanA"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>