title: Spring boot: Read a file PATH from "application.properties"
body: <p>I'm using Spring Boot and I want to read a file path from the resources/application.properties file and set its value to a String in a Java class:</p>
  
  <p><strong>resources/application.properties</strong></p>
  
  <pre><code>mypath=dir/file.ext
  </code></pre>
  
  <p><strong>resources/application-context.xml</strong></p>
  
  <pre><code>&lt;context:property-placeholder location="classpath:application.properties" /&gt;
  </code></pre>
  
  <p><strong>MyJavaClass.java</strong></p>
  
  <pre><code>@Component
  public class MyJavaClass{ 
  
      @Value("${mypath}") 
      String mypath;
  
      public void printme(){
          System.err.println(mypath);
      }
  }
  </code></pre>
  
  <p>When I try to print the String, it always prints "null". What am I doing wrong? Thanks.</p>