Tomcat serving static resources on Spring MVC app

Rigoni picture Rigoni · Sep 19, 2010 · Viewed 9.9k times · Source

I'm building a Spring MVC application, and the frontController servlet is mapped in "/" intercepting all requests, I'd to be able to serve the static contents (.js,.css,.png...) from tomcat and not by Spring. My app structure is

-webapp/
   styles/
   images/
   WEB-INF/
          views/

By default, because the frontController is mapped on the context root of my app its handles all requests but don't serve any static resource. The mvc configurarion for static resources is follow.

<mvc:resources mapping="/resources/**" location="/"/>

And the page's code is:

<img src="resources/images/logo.png" />

I need to configure Tomcat to serve the static resources with no spring interaction.

Any suggestion?

Answer

nos picture nos · Sep 19, 2010

You can remap tomcats default servlet (which handles static content), e.g.

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/images/*</url-pattern>
</servlet-mapping>