Tomcat在Spring MVC应用上提供静态资源 [英] Tomcat serving static resources on Spring MVC app
问题描述
我正在构建一个Spring MVC应用程序,并且frontController servlet被映射在"/"中以拦截所有请求,我希望能够提供静态内容(.js,.css,.png ...)来自tomcat,而不是Spring. 我的应用程序结构是
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/
默认情况下,因为frontController映射到我的应用的上下文根上,所以它可以处理所有请求,但不提供任何静态资源. 静态资源的mvc配置如下.
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="/"/>
页面的代码是:
<img src="resources/images/logo.png" />
我需要将Tomcat配置为在没有弹簧交互的情况下提供静态资源.
I need to configure Tomcat to serve the static resources with no spring interaction.
有什么建议吗?
推荐答案
您可以重新映射tomcats默认servlet(用于处理静态内容),例如
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>
这篇关于Tomcat在Spring MVC应用上提供静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!