【发布时间】:2016-06-28 22:11:36
【问题描述】:
我正在尝试使用VersionResourceResolver 来防止缓存旧的 js 和 css。目前我正在为我的 Spring 使用基于 XML 的配置。我刚刚复制了这段代码:
<mvc:resources mapping="/resources/**" location="/public-resources/">
<mvc:resource-chain>
<mvc:resource-cache/>
<mvc:resolvers>
<mvc:version-resolver>
<mvc:content-version-strategy patterns="/**"/>
</mvc:version-resolver>
</mvc:resolvers>
</mvc:resource-chain>
</mvc:resources>
并将其放置在 DispatcherServlet 调用的我的 xml 中,以便启动我的 Web 应用程序。将此代码放入我的 servlet.xml 后,我有这样的东西:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="/WEB-INF/application.properties" />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
<mvc:resources mapping="/resources/**" location="/resources/">
<mvc:resource-chain>
<mvc:resource-cache />
<mvc:resolvers>
<mvc:version-resolver>
<mvc:content-version-strategy patterns="/**"/>
</mvc:version-resolver>
</mvc:resolvers>
</mvc:resource-chain>
</mvc:resources>
<mvc:resources mapping="/sources/**" location="/sources/" />
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<property name="proxyTargetClass" value="true" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="pt_BR" />
</bean>
</beans>
Eclipse 告诉我 servlet.xml 中有 2 个错误:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'mvc:resource-cache'. One of '{"http://www.springframework.org/schema/mvc":resolvers, "http://www.springframework.org/schema/mvc":transformers}' is expected.
cvc-complex-type.4: Attribute 'resource-cache' must appear on element 'mvc:resource-chain'.
我不知道会发生什么,因为我使用的是最新版本的 mvc.xsd。
如果有人能帮助找出我的错误,我将不胜感激。
【问题讨论】:
标签: java spring spring-mvc xml-parsing