Search code examples
javaservletsspring-mvcurl-patterntuckey-urlrewrite-filter

Spring MVC REST : static files unaccessible because of url-pattern


My Spring Dispatcher servlet url-pattern is /* (as spring MVC REST suggests)
Now all the request are resolved by this Servlet. even CSS/JS/Images also get resolved and handled by servlet..

So, Spring MVC tries to find controller.. :(

How to bypass this? Is there any standard way out of this problem??

& Don't want to change url-pattern to /rest/* (so, other static resources get accessed by /css/ or /js etc.)


Solution

  • You can map your controllers to a smaller set of URLS (i.e. /app/*), and then rewrite the URLs that your users actually see so that they don't even know about. Have a look at the mvc-basic webapp sample, particularly web.xml and urlrewrite.xml to see how this is done.