title: Inject File from classpath using Spring Environment
body: <p><strong>My problem: how can I inject a <code>File</code> in my class using the <code>Environment</code> variable?</strong></p>
  
  <p>I specify in a <code>properties</code> the path of a file I need to read:</p>
  
  <pre><code>myFile.path=classpath:myFile.json
  </code></pre>
  
  <p>I used to have an XML application context defining a <code>property-placeholder</code> for that <code>properties.file</code> and then I simply could inject my file using the <code>@Value</code>:</p>
  
  <pre><code>@Value("${myFile.path}")
  private File myFile;
  </code></pre>
  
  <p>Yet, now I'd like to do something like:</p>
  
  <pre><code>@Inject
  private Environment environment;
  
  private File myFile;
  
  @PostConstruct
  private void init() {
      myFile = environment.getProperty("myFile.path", File.class);
  }
  </code></pre>
  
  <p>But an Exception is thrown: </p>
  
  <pre><code>Caused by: java.io.FileNotFoundException: 
      classpath:myFile.json (No such file or directory)
  </code></pre>
  
  <p>I also tried something like <code>myFile = environment.getProperty("myFile.path", Resource.class).getFile();</code> but an other exception is thrown.</p>
  
  <p><strong>How can I achieve to inject my file knowing that the path defined in the properties can be absolute or classpath relative?</strong></p>