`
carvin
  • 浏览: 209645 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring mvc 3.0.4 RESTful 如何处理静态资源的访问

阅读更多
Spring MVC3.0 开始全面支持REST, 但是在处理静态资源方面一直不太理想,在3.0.4发布之前都是通过上一篇文章中介绍的那两种方式处理,但是在3.0.4版本中有了新的处理方式:
1、在spring mvc的配置文件中增加如下标签:
<mvc:default-servlet-handler/>

在spring reference中解释如下:
This tag allows for mapping the DispatcherServlet to "/" (thus overriding the mapping of the container's default Servlet), while still allowing static resource requests to be handled by the container's default Servlet. It configures a DefaultServletHttpHandler with a URL mapping (given a lowest precedence order) of "/**". This handler will forward all requests to the default Servlet. To enable this feature using the default setup, simply include the tag in the form: ....

2、现在如果用这个标签,因为spring官方的http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 还没有更新。所以会报错,有以下方法可以代替:
1)手动将3.0.4版本中的spring-mvc-3.0.xsd添加到本地的xml catalog 中,xsd所在位置:
org.springframework.web.servlet-3.0.4.RELEASE.jar\org\springframework\web\servlet\config。
2)用另外的配置方法代替:
<bean class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
   <property name="urlMap">
	<util:map>
		 <entry key="/**"
	value="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
	</util:map>
   </property>
</bean>
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />

分享到:
评论
2 楼 carvin 2012-07-17  
非常抱歉,现在才看到留言。
第一种解决办法,现在新版本的Spring应该已经添加了那个标签的支持了。
第二种解决办法,在配置文件开始的地方添加Util的内容,如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
     http://www.springframework.org/schema/util
     http://www.springframework.org/schema/util/spring-util-3.0.xsd">
1 楼 benfreer 2012-06-07  
菜鸟哈~问一下
第一种解决方法,是不是在其他xml所在位置 新建一个xml 把org.springframework.web.servlet-3.0.4.RELEASE.jar\org\springframework\web\servlet\config 中mvc的内容拷贝进去

其他的xml 如配置servlet的xml里怎么写? 怎么写引用?

第二种解决方法,
<util:map>  报错 没有配置util 在头中怎么设置?

谢谢~

相关推荐

Global site tag (gtag.js) - Google Analytics