title: Java Spring Access Static Resources outside application
body: <p>I want to enable my users to upload images which are then stored on the server.
  Since putting those images inside the applications resources/static-folder would remove them with every new deployment I want to store and access those images outside of my Spring application.</p>
  
  <p>I still need to display the images in my html-Context so what I am trying to do is to map a path (e.g. "userimages") to a location outside of my application (e.g. "/home/userimages/" So that when the url localhost:8080/userimages/hi.jpg is called, the image from /home/userimages/hi.jpg is returned.</p>
  
  <p>I found the function addResourceHandlers that seems to be able to do exactly this, but I have trouble implementing it. For starters I am unsure whether to extend WebMvcConfigurationSupport or WebMvcConfigurationAdapter or implement WebMvcConfigurer. None seems to work.
  I also tried around with different @ above that class like @EnableWebMvc etc. - nothing changed.
  Some sites suggested moving the Class to the same package as the application - also didn't work.</p>
  
  <p>I think that the function addResourceHandlers is not even called and I don't know how to make sure it is. This is currently my code:</p>
  
  <pre><code>package global;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  
  @Configuration
  @EnableWebMvc
  public class StaticResourceProvider implements WebMvcConfigurer {
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          //This never gets printed
          System.out.print("Adding resource handler");
          registry
                  .addResourceHandler("/user-images/**")
                  //for Unix: file:/opt/files
                  //TODO: use path variable here
                  .addResourceLocations("file:///C:/Users/Juliette/Pictures/");
      }
  }
  </code></pre>
  
  <p>And the entry point to my application:</p>
  
  <pre><code>package controller;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  
  @SpringBootApplication
  public class Application  extends SpringBootServletInitializer {
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(Application.class);
      }
  
      public static void main(String[] args) {
          //TODO: remove the first array element and read it as the name of this instance
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>
  
  <p>Can someone tell me what my mistake is? Currently when I access localhost:8080/user-images/nameOfSomeImage.jpg only a white page is returned and no message shows up in the server log.</p>