title: How to access a resource file in src/main/resources/ folder in Spring Boot
body: <p>I'm trying to access xsd in src/main/resources/XYZ/view folder where XYZ/view folder are created by me and folder has abc.xsd which I need for xml validation.</p>
  
  <p>When I try to access the xsd every time I get the result as null,</p>
  
  <p>I have tried as,</p>
  
  <p>1) </p>
  
  <pre><code>@Value(value = "classpath:XYZ/view/abc.xsd")
  private static Resource dataStructureXSD;
  InputStream is = dataStructureXSD.getInputStream();
  Source schemaSource = new StreamSource(is);
  Schema schema = factory.newSchema(schemaSource);
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>Resource resource = new ClassPathResource("abc.xsd");
  File file = resource.getFile();
  </code></pre>
  
  <p>and many more trails I made to get the resource or classloader etc.</p>
  
  <p>Finally I get the xsd with,</p>
  
  <p>File file = new File(new ClassPathResource("/src/main/resources/XYZ/view/abc.xsd").getPath());
  Schema schema = factory.newSchema(file);</p>
  
  <p>and it is working, I want to know why the other two trails would have gone wrong or why it didn't work for me and fine for others. :(</p>
  
  <p>Or is there other good way of doing it which I'm missing</p>