dimanche 19 avril 2015

Spring MVC Path Pattern Matching Doesn't Handle Dashes

I have a @Configuration class that extends WebMvcConfigurerAdapter with a method similar to this:



@Override
public void addResourceHandlers(ResourceHandlerRegistry r) {
final Integer CACHE_LONGTERM = 31536000;
r.addResourceHandler("jQuery-File-Upload*/**").addResourceLocations("/jQuery-File-Upload-9.9.3").setCachePeriod(CACHE_LONGTERM);
}


When trying to access those static resources Spring does not match the URL (e.g. http://localhost:8080/app/jQuery-File-Upload-9.9.3/js/file.js) with the configured resource handler (404 error or similar). If I change the name of the directory on the filesystem though and remove the initial dashes from the pattern, then it works (e.g. using http://localhost:8080/app/jQueryFileUpload-9.9.3/js/file.js):



@Override
public void addResourceHandlers(ResourceHandlerRegistry r) {
final Integer CACHE_LONGTERM = 31536000;
r.addResourceHandler("jQueryFileUpload*/**").addResourceLocations("/jQueryFileUpload-9.9.3").setCachePeriod(CACHE_LONGTERM);
}


I've tried to debug this a little bit and can see Spring uses org.springframework.util.AntPathMatcher in order to process these patterns. The code in that class is pretty messy though and I know Spring has had pattern/path related bugs in the past. Is this another defect? How can I modify the code above so it works without having to remove the dashes as I did in the workaround?


Using Spring 4.1.6 and Java 8.


Aucun commentaire:

Enregistrer un commentaire