Spring MVC REST: static files unavailable due to url template

My Spring Dispatcher Servlet URL // (as Spring MVC REST suggests)
Now all requests are resolved by this servlet. even CSS / JS / Images are also resolved and processed by the servlet.

So, Spring MVC is trying to find the controller .. :(

How to get around this? Is there a standard way out of this problem?

& Do not want to change the url template in / rest / * (therefore, other static resources get access to / css / or / js, etc.)

+4
source share
3 answers

You can map your controllers to a smaller set of URLS (e.g. / app / *), and then rewrite the URLs that your users actually see so they don’t even know. Check out the mvc-basic webapp sample , especially web.xml and urlrewrite.xml, to see how this is done.

+5
source

Map the Spring dispatcher to a subsection of the URLs and use Tuckey to rewrite the URLs the user is dealing with.

http://www.example.org/app/controller/action β†’ http://www.example.org/controller/action

+2
source

Just a heads-up update about this: the default rewrite configuration defined in the Spring sample didn't work out of the box for me. Rules for overwriting style sheets, scripts, etc. They were still processed in the / app / * rule, and then DispatchServlet processed, which is undesirable.

I had to add the last="true" attribute to the styles / scripts / images rules to indicate that no other rules should apply, and I had to use the FreeMarker Spring URL macro in any ways to add CSS / JS.

Just in case, someone is faced with the same problem.

0
source

All Articles