title: Serving Static resources from file system | Spring Boot Web
body: <p>Using a Spring Boot web application I trying to serve my static resource from a file system folder outside my project.</p>
  
  <p>Folder structure looks like:-</p>
  
  <pre><code>          src
               main
                   java
                   resources
               test
                   java
                   resources
            pom.xml
            ext-resources   (I want to keep my static resources here)
                   test.js
  </code></pre>
  
  <p>Spring Configuration:-</p>
  
  <pre><code>@SpringBootApplication
  public class DemoStaticresourceApplication extends WebMvcConfigurerAdapter {
  
      public static void main(String[] args) {
          SpringApplication.run(DemoStaticresourceApplication.class, args);
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/test/**").addResourceLocations("file:///./ext-resources/")
                  .setCachePeriod(0);
      }
  }
  </code></pre>
  
  <p>Hitting '<a href="http://localhost:9999/test/test.js" rel="noreferrer">http://localhost:9999/test/test.js</a>' in my browser gives back a 404.</p>
  
  <p>How should I configure ResourceHandlerRegistry to serve static resources from the above mentioned 'ext-resources' folder?</p>
  
  <p>I should be able to switch cache on/off for dev/prod environment.</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Giving absolute file path works:-</p>
  
  <pre><code>@Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/test/**")
                  .addResourceLocations(
                          "file:///C:/Sambhav/Installations/workspace/demo-staticresource/ext-resources/")
                  .setCachePeriod(0);
  }
  </code></pre>
  
  <p>How can I provide relative location? Absolute path will make my life tough during build &amp; deploy process.</p>