title: Expose Properties file to Java via Spring
body: <p>I am trying to use Spring to allow my Java classes to access a properties file.  I have done quite a bit of googleing and there seems to be several ways of doing this.  I have tried to use two of the different ways, and they are both failing.</p>
  
  <p><strong>Attempt 1</strong><br/>
  XML</p>
  
  <pre><code>&lt;bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"&gt;
      &lt;property name="location" value=classpath:config.properties /&gt;
      &lt;property name="ignoreUnresolvablePlaceholders" value="true"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Java</p>
  
  <pre><code>public class App
  {
      @Autowired
      private static Environment env;
  
      public static void main(String[] args)
      {
          System.out.println(env.getProperty("DatabaseName"));
      }
  }
  </code></pre>
  
  <p><strong>Attempt 2</strong><br/>
  XML</p>
  
  <pre><code>&lt;util:properties id="myProperties" location="classpath:config.properties"/&gt;
  </code></pre>
  
  <p>Java</p>
  
  <pre><code>public class App
  {
      @Resource(name="myProperties")
      private static Properties myProperties;
  
      public static void main(String[] args)
      {
          System.out.println(myProperties.getProperty("DatabaseName"));
      }
  }
  </code></pre>
  
  <p>In both cases I get a Null Pointer Exception when calling the "getProperty" method.  I am new to Spring and am guessing I am missing something simple.  In addition to getting these attempts to work, I would like to know what is the "best" way to expose a properties file with Spring.<br/>
  Thank you in advance for any help.</p>