允许使用Spring MVC mvc:resources标记进行缓存

dig*_*oel 6 caching spring-mvc http-headers

我已经在我的webapp的根目录下配置了Spring 3 MVC Dispatcher servlet,并使用mvc:resources来提供静态内容,如文档中所述:http: //static.springsource.org/spring/docs/3.0.x/弹簧框架参考/ HTML/mvc.html#MVC的静态资源

Google的Chrome浏览器审核告诉我,资源显然是不可缓存的.以下是与响应一起发送的相同浏览器的标题:

Cache-Control:max-age=31556926, must-revalidate
Content-Length:1022
Content-Type:image/png
Date:Tue, 11 Jan 2011 00:20:07 GMT
Expires:Wed, 11 Jan 2012 06:08:53 GMT
Last-Modified:Mon, 29 Nov 2010 19:53:48 GMT
Run Code Online (Sandbox Code Playgroud)

那么,为了使资源可以缓存,我需要什么?

mad*_*ead 1

也许 org.springframework.web.servlet.mvc.WebContentInterceptor 可以帮助你?只需将其添加到拦截器列表中即可:

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.mvc.WebContentInterceptor">
        <property name="cacheMappings">
            <props>
                <prop key="/ajax/promoCodes">300</prop>
                <prop key="/ajax/options">0</prop>
            </props>
        </property>
    </bean>
</mvc:interceptors>
Run Code Online (Sandbox Code Playgroud)