title: spring boot loading property file from custom folder
body: <p>I need to load a property file from src/main/resources/config folder. The loading part is written in a common dependency project where we dont have any control. We are just passing the file name expressed through a dependency. The code snippet in the dependent jar is like below, the standard resource loading.</p>
  
  <p><code>InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(propertyFileName);</code></p>
  
  <p>Spring will always look for recources under recources folder directly, in this case its unable to load the file as its in the custom folder and its not under classpath.</p>
  
  <p>How do we explicitly set the custom folder as additional classpath folder?</p>
  
  <p>With maven we could do something like below which works fine. Is there any OOTB way to achieve this with annotation in spring boot?</p>
  
  <pre><code>    `&lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
          &lt;/resource&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources/config&lt;/directory&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;`
  </code></pre>
  
  <h2>Updated</h2>
  
  <pre><code>    `// This works if config.properties is directly under resource folder
      // What if config.properties is under resources/config folder.
      // Dont say to pass argument as /config/config.properties, there are some other limitations.
      // So in that case with the same approach, config should come under classpath, so that the below
      // method will work always when the property name is passed.
      // As mentioned earlier, we can use maven resource settings to achieve this.
      // The question here is, is there any way to explicitely advise spring to load property from this folder.
      // I have seen something like loader.path config, not sure that helps!
      InputStream stream = SpringBootStarter.class.getResourceAsStream("/config.properties");`
  </code></pre>