title: Spring MVC resource versioning adding the ResourceUrlEncodingFilter
body: <p>I'm trying to get the new resource versioning from 4.1 working. From </p>
  
  <p><a href="http://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources" rel="nofollow">http://spring.io/blog/2014/07/24/spring-framework-4-1-handling-static-web-resources</a></p>
  
  <p>and</p>
  
  <p><a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-config-static-resources" rel="nofollow">http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-config-static-resources</a></p>
  
  <p>I can't seem to register the ResourceUrlEncodingFilter correctly.  How do you do that so it picks up urls in jsp?
  I'm using javaconfig and in my extended WebMvcConfigurerAdapter --> addResourceHandlers method I have</p>
  
  <pre><code>registry.addResourceHandler("/static/**")
              .addResourceLocations("classpath:/META-INF/resources/static/")
              .resourceChain(true)
              .addResolver(
                      new VersionResourceResolver()
                              .addFixedVersionStrategy("1.1.0", "/**/*.js")
                              .addContentVersionStrategy("/**"));
  </code></pre>
  
  <p>This seems to work as I can get the changes in a controller</p>
  
  <pre><code>@Autowired
  private ResourceUrlProvider resourceUrlProvider;
  
  
  @RequestMapping(value = "/test", method = RequestMethod.GET)
  public String homePub() {
  
      logger.debug("js =  '{}'", this.resourceUrlProvider.getForLookupPath("/static/test.js"));
      logger.debug("css =  '{}'", this.resourceUrlProvider.getForLookupPath("/static/test.css"));
  
      return "test";
  }
  </code></pre>
  
  <p>Will output</p>
  
  <pre><code>DEBUG TestController - js =  '/static/1.1.0/test.js'
  DEBUG TestController - css = '/static/styles/test-4c517674c05348b2aa87420e7adc420b.css'
  </code></pre>
  
  <p>Initially urls in jsp's are ignored so I added</p>
  
  <pre><code>container.addFilter("resourceUrlEncodingFilter",  ResourceUrlEncodingFilter.class).addMappingForUrlPatterns(
              null, true, "/*");
  </code></pre>
  
  <p>To my implementation of WebApplicationInitializer</p>
  
  <p>This gives the exception below</p>
  
  <pre><code>java.lang.IllegalStateException: Failed to determine lookup path: /test/static/test.js
  </code></pre>
  
  <p>So at least I know the filter is being called it just hasn't picked up my handlers
  I tried adding a resource handler for /test/static/** as well but that didn't help.
  Changing the isMatchAfter to false stops the exception but the filter doesn't seem to be called.</p>
  
  <p>The jsp is question is very simple</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %&gt;
  
  &lt;c:url value='/static/test.js'/&gt;
  </code></pre>
  
  <p>So I guess that's not how to set up the ResourceUrlEncodingFilter, how should it be added</p>