title: BeanInstantiationException - Constructor threw exception; nested exception is java.lang.NullPointerException
body: <p>I've a weird problem of unable to instantiate a bean which is injected to another bean.</p>
  
  <p>The <code>PropertiesUtil</code> is the bean in question. It's injected to the <code>LoginController</code> class as follows in my <code>sn-servlet.xml</code></p>
  
  <pre><code>  &lt;bean name="/Login.html" class="org.sn.auth.LoginController"&gt;
      &lt;property name="dbUtil" ref="dbUtil"/&gt;
      &lt;property name="propertiesUtil" ref="propertiesUtil"/&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>and my PropertiesUtil.java is </p>
  
  <pre><code>public class PropertiesUtil {
  
      private Properties properties;
  
      public PropertiesUtil() {
          properties = new Properties();
          try {            
                  properties.load(ClassLoader.getSystemResourceAsStream(
                                      "/resources/messages.properties"));
          }
          catch (IOException ioException) {
              ioException.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>And the NullPointerException occurs at the line where I try to use the <code>properties</code> to <code>load</code> a resource. I'm really confused why it's null when I'm clearly instanting it in the previous line.</p>
  
  <p>I've also tried injecting the <code>properties</code> instance as a <code>constructor-arg</code> and also as a <code>property</code> from the <code>sn-servlet.xml</code>, but all in vain.</p>
  
  <p>Is there something like I'm not supposed to do any operations in a constructor when that bean is spring-injected to some other class?</p>
  
  <p>Thanks for any ideas!</p>