On my current project we’re using Spring 3 MVC and have a requirement to implement clean URLs – something like /category/subcategory/id. So we’ve mapped the DispatchServlet to any URL like this:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
We’d like all requests to this application to go through one method of one controller for now. So that method as an annotation like:
@RequestMapping("/**")
However this literally maps everything (of course), including requests to what should be static resources, like things in img/, js/ and css/. Is there a way we can exclude these static resource containing directories while capturing anything else with the one @RequestMapping annotation?
The solution turned out to be to move the @RequestMapping annotation to the class level, as opposed to the method. The Controller was then made to implement Controller and the controller’s logic was shifted to the required handleRequest method.
For whatever reason this works fine. I don’t yet understand enough about Spring MVCs internal logic to understand exactly why it works but it does. I’d have hoped there’d be a more transparent and “Spring” way to do it.