title: How to configure spring-boot to serve static files using springmvc-router
body: <p>I'm quite new to spring-mvc, so please let me know if I'm using it mistakenly or if there something I'm misunderstanding.</p>
  
  <p>I cannot serve static files on a spring-boot project. There is no problem with the views generated by my controllers.</p>
  
  <p>My <strong><code>spring-boot</code></strong> project is using <strong><code>springmvc-router</code></strong> to map the urls for the controllers in a single file instead of using <code>@RequestMapping</code> on each controller.</p>
  
  <p>According to the documentation, I have to add the Router to my Spring MVC configuration; in my case, I need to extend the <code>RouterConfigurationSupport</code> class. When I put this configuration (just like it is in the documentation) it causes the requests of static files to fail (it gives me the "white label error" and 404 in the log).</p>
  
  <p>This is the configuration class:</p>
  
  <pre><code>import org.resthub.web.springmvc.router.RouterConfigurationSupport;
  @Configuration
  @ComponentScan(basePackages = "my.project.demo.controllers")
  // You should not use the @EnableWebMvc annotation
  public class WebAppConfig extends RouterConfigurationSupport {
      @Override
      public List&lt;String&gt; listRouteFiles() {
          List&lt;String&gt; routeFiles = new ArrayList&lt;String&gt;();
          routeFiles.add("classpath:routes.conf");
          return routeFiles;
      }
  }
  </code></pre>
  
  <p>I've found that <code>RouterConfigurationSupport</code> class extends (in some way) <code>WebMvcAutoConfiguration</code>.</p>
  
  <p>In the browser, the message displayed is:</p>
  
  <pre><code>Whitelabel Error Page
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  Tue Apr 28 11:43:10 CDT 2016
  There was an unexpected error (type=Not Found, status=404).
  No message available
  </code></pre>
  
  <p>In the logs, it prints:</p>
  
  <pre><code>o.s.web.servlet.PageNotFound    : No mapping found for HTTP request with URI [/css/bootstrap.min.css] in DispatcherServlet with name 'dispatcherServlet'
  </code></pre>
  
  <p>The springmvc-router works well for the views of my controllers, but now I cannot serve static files (like css or js).</p>
  
  <p>I have the notion that it is possible to 'manually' configure the static file resolution, but I'd prefer to take advantage of the spring-boot auto configuration.</p>
  
  <p>I've noticed that if I skip the configuration class mentioned above, the spring-boot auto configuration works normally and the static files get served, but then spring cannot find the routes for my controllers (obviously).</p>
  
  <hr>
  
  <p>This is similar to this question <a href="https://stackoverflow.com/questions/22267191/is-it-possible-to-extend-webmvcconfigurationsupport-and-use-webmvcautoconfigurat">Is it possible to extend WebMvcConfigurationSupport and use WebMvcAutoConfiguration?</a> since I'm trying to add specific custom configuration but keeping the other configuration as default.</p>
  
  <p>So I tried using a BeanPostProcessor like in this answer
  <a href="https://stackoverflow.com/a/28594582">https://stackoverflow.com/a/28594582</a>
  and another similar in this issue's comment
  <a href="https://github.com/spring-projects/spring-boot/issues/5004#issuecomment-173714159" rel="nofollow noreferrer">https://github.com/spring-projects/spring-boot/issues/5004#issuecomment-173714159</a> but I still cannot load static files.</p>
  
  <p>Another suggesion I've read was to copy the code from WebMvcAutoConfiguration class and append it to my specific configuration, but I don't really like this solution.</p>
  
  <p>It might be not relevant, but I'm using a library for working with Jade as the templates' language.</p>
  
  <hr>
  
  <ul>
  <li><em>Although I have already found a fix to this, I feel that I need to post this question because I found no other similar cases and because maybe there is another solution, hopefully better than mine.</em></li>
  </ul>