title: Unable to read XML file with ApplicationContext into a InputStream
body: <p>I am trying to load a XML file into a input stream with spring-mvc's <code>ApplicationContext</code>. But I am not able to read the file and I am getting conflicting information. </p>
  
  <p>I am trying to load a xml file into a <code>InputStream</code> and find the file via:</p>
  
  <pre><code>ApplicationContext ctx =
    new ClassPathXmlApplicationContext(new String[]{"classpath*:config/validation.xml"});
  </code></pre>
  
  <p>I then what to initialize my <code>InputStream</code> from the <code>ApplicantionContext</code> but I am unclear how to. Right now I have:</p>
  
  <pre><code>private InputStream forms = getClass().getClassLoader().getResourceAsStream("/validation.xml");
  </code></pre>
  
  <p>However the issue at the moment is I cannot even find the file.</p>
  
  <p>Conflicting information:</p>
  
  <p>I am put the files under resources and again in <code>webapp-&gt; WEB-INF-&gt; config</code> to try to figure out where it could be loaded from.</p>
  
  <pre><code>ApplicationContext ctx =
      new ClassPathXmlApplicationContext(new String[]{"classpath*:config/validation.xml"});
  </code></pre>
  
  <p>Say <code>FOUND!!!!!!!!!!!</code></p>
  
  <pre><code>public Validator() {
  
          this.testResource();
  
          if(ctx != null){
              System.out.println("FOUND!!!!!!!!!!!!!!!!!!!!"+ctx); //this prints
          }else{
              System.out.println("NOT FOUND");
          }
      }
  </code></pre>
  
  <p>Output: </p>
  
  <blockquote>
    <p>FOUND!!!!!!!!!!!!!!!!!!!!org.springframework.beans.factory.support.DefaultListableBeanFactory@635bc5cc: defining beans []; root of factory hierarchy</p>
  </blockquote>
  
  <p>However this says the file cannot be found:</p>
  
  <pre><code>private void testResource(){
  
      Resource resource =
              this.ctx.getResource("classpath*:/validation.xml");
  
      try{
          InputStream is = resource.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(is));
  
          String line;
          while ((line = br.readLine()) != null) {
              System.out.println(line);
          }
          br.close();
  
      }catch(IOException e){
          System.out.println("ERROR it is not found: ");
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>--------------------------Update 1-----------------------</p>
  
  <p>I now have the following and it too is giving me conflicting information saying found then an IOException:</p>
  
  <pre><code>@Configuration
  public class Validator {
  
      private InputStream forms;
      private ValidatorResources resources;
  
      ApplicationContext ctx =
              new ClassPathXmlApplicationContext(new String[]{"classpath*:config/validation.xml"});
  
      private Resource resource = this.ctx.getResource("classpath*:validation.xml");
  
      public Validator() {
  
          if(resource != null){
              System.out.println("FOUND!!!!!!!!!!!!!!!!!!!!"+resource);
          }else{
              System.out.println("NOT FOUND");
          }
  
          this.runInputStream();
      }
  
      private void runInputStream(){
          try{
              this.forms = this.resource.getInputStream();
              this.resources = new ValidatorResources(this.forms);
  
          }catch (IOException ex) {
              System.out.println("runInputStream IOException: "+ex);
          }catch (SAXException e) {
              System.out.println("runInputStream SAXException: "+e);
          }catch (Exception e){
              System.out.println("ERROR-------------"+e);
          }
  
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <blockquote>
    <p>FOUND!!!!!!!!!!!!!!!!!!!!class path resource
    [classpath*:validation.xml] runInputStream IOException:
    java.io.FileNotFoundException: class path resource
    [classpath*:validation.xml] cannot be opened because it does not exist</p>
  </blockquote>