【发布时间】:2011-07-06 13:29:42
【问题描述】:
我使用的是 Spring 3.0.5。我的所有静态资产都放在我的网络应用程序根目录下名为“static”的文件夹中(与 WEB-INF 处于同一级别)。如何将“http://mydomain.com/context-path/static/some-asset”形式的 URL 映射到我的“静态”文件夹?
这很复杂,因为我有一个映射到根上下文的视图解析器(来自我的 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:resources 似乎并没有治愈痛苦。我添加到我的 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 调度程序的 Servlet.service() 引发异常 javax.servlet.ServletException:处理程序没有适配器 [com.myco.systems.leadsmonitor.web.controller.HomeController@6870c52d]:您的处理程序是否实现了像 Controller 这样的受支持接口?”当我访问我的主页“/”时。
【问题讨论】:
-
什么是parentContext.xml?你通常把它放在 dispatcher-servlet.xml
标签: java spring spring-mvc