我使用Spring 3.0.5。我將所有靜態資產放在我的web-app根目錄下的一個名爲「static」的文件夾中(與WEB-INF處於同一級別)。如何將表單「http://mydomain.com/context-path/static/some-asset」的URL映射到我的「靜態」文件夾?如何在我的Spring應用程序中映射靜態資產?
這是事實,我有一個映射到根上下文(從我的web.xml)視圖解析器複雜...
<!-- Declare a Spring MVC DispatcherServlet as usual -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext
instead of the default XmlWebApplicationContext -->
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
好,感謝您的幫助, - 戴夫
PS - 添加mvc:資源似乎無法彌補痛苦。我加入到我的parentContext.xml文件...
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:resources mapping="/static/**" location="/static/"/>
但隨後得到了例外,「重度:Servlet.service()進行servlet調度拋出異常 javax.servlet.ServletException:無適配器處理程序[COM .myco.systems.leadsmonitor.web.controller.HomeController @ 6870c52d]:你的處理程序是否實現了像Controller這樣的受支持的接口?「當我訪問我的主頁「/」。
什麼是parentContext.xml?你通常把它放在dispatcher-servlet.xml中 – Bozho