title: Spring Boot app not serving static content
body: <p>I am using Spring Boot, and am trying to make my static resources (CSS, JS, Fonts) available when deployed. The source code is available for you to look at or clone from <a href="https://github.com/joecracko/StaticResourceError" rel="noreferrer">https://github.com/joecracko/StaticResourceError</a>.</p>
  
  <p>Right now my CSS, JS, and Font files are not visible to my deployed website.</p>
  
  <p><strong>Here is my project directory structure:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/rQhlY.png" alt="Here is my project directory structure"></p>
  
  <p><strong>Here is the root directory of the compiled JAR:</strong> I assure you the files are present in their respective folders.</p>
  
  <p><img src="https://i.stack.imgur.com/DXhr2.png" alt="enter image description here"></p>
  
  <p><strong>Here is the network error I am seeing:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/8yrZ5.png" alt="enter image description here"></p>
  
  <p><strong>And here are my sources provided by chrome tools.</strong> Note that bar.css appears empty here. You may look at my source code to see that it is not empty.</p>
  
  <p><img src="https://i.stack.imgur.com/Y7wfL.png" alt="enter image description here"></p>
  
  <p><strong>Here is my homepage.html</strong></p>
  
  <pre><code>&lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  
  &lt;!-- Main Styles --&gt;
  &lt;link rel="stylesheet" href="/css/bar.css" /&gt;
  &lt;script src="/js/foo.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;Welcome to Foo!&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Here is my Web App Initializer</strong> (FooWebAppInitializer.java)</p>
  
  <pre><code>public class FooWebAppInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext container) {
  
          AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
          rootContext.register(ServletConfig.class);
  
          // Manage the lifecycle of the root application context
          container.addListener(new ContextLoaderListener(rootContext));
  
          //Spring Security
          container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain"))
              .addMappingForUrlPatterns(null, false, "/*");
  
          // Register and map the dispatcher servlet
          ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcherServlet", new DispatcherServlet(rootContext));
          dispatcher.setLoadOnStartup(1);
          dispatcher.addMapping("/*");
          dispatcher.addMapping("*.css");
          dispatcher.addMapping("*.eot");
          dispatcher.addMapping("*.svg");
          dispatcher.addMapping("*.ttf");
          dispatcher.addMapping("*.woff");
          dispatcher.addMapping("*.map");
          dispatcher.addMapping("*.js");
          dispatcher.addMapping("*.ico");
      }
  }
  </code></pre>
  
  <p><strong>Here is my Servlet Configuration</strong> (ServletConfig.java)</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan({"com.foo"})
  public class ServletConfig extends WebMvcAutoConfiguration{
  
      @Bean
      MultipartResolver multipartResolver() {
          return new StandardServletMultipartResolver();
      }
  
      @Bean
      public ResourceBundleMessageSource messageSource() {
          ResourceBundleMessageSource source = new ResourceBundleMessageSource();
          source.setBasename("messages");
          return source;
      }
  }
  </code></pre>
  
  <p><strong>And for kicks, My Spring Security Config</strong> (WebSecurityConfig.java)</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .anyRequest().permitAll();
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web.ignoring().antMatchers("/resources/**"); // #3
      }
  }
  </code></pre>