title: Serving static files with Spring 4 (Annotations)
body: <p>I have simple Spring 4 application:</p>
  
  <pre><code>package proj;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  
  @SpringBootApplication
  public class Application {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  }
  </code></pre>
  
  <p>I'd like to serve static content from <strong>/resources</strong> folder, also I have file <strong>resources/1.txt</strong> which I made for testing. </p>
  
  <p>I created class <strong>Application</strong> in the root folder, also I created another folder <strong>config/</strong> in the root folder, in the <strong>config/</strong> I created a new class <strong>WebMvcConfig</strong> and added the code:</p>
  
  <pre><code>package proj.config;
  
  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.WebMvcConfigurerAdapter;
  
  @Configuration
  @EnableWebMvc
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addResourceHandlers(final ResourceHandlerRegistry registry) {
          registry
                  .addResourceHandler("/resources/**")
                  .addResourceLocations("/resources/");
      }
  }
  </code></pre>
  
  <p>Then I tried to get file <strong>1.txt</strong> from my <strong>/resources</strong> folder by query:</p>
  
  <blockquote>
    <p><a href="http://localhost:8080/resources/1.txt" rel="nofollow noreferrer">http://localhost:8080/resources/1.txt</a></p>
  </blockquote>
  
  <p>But I get <strong>404 error not found</strong>. I can't understand why it doesn't work.</p>
  
  <p>I will really appreciate if somebody can help me to solve that problem.</p>