簡體   English   中英

基於配置xml的資源版本控制(Spring)

[英]Resource Versioning with configuration xml-based (Spring)

我正在嘗試使用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后會發生什么。
如果有人能幫忙找到我的錯誤,我很感激。

是的,所以我的一所大學已經解決了這個問題。 Spring文檔是錯誤的,使用基於XML的配置的資源版本控制的正確方法是:

<mvc:resources mapping="/resources/**" location="/public-resources/">
    <mvc:resource-chain resource-cache="true">
        <mvc:resolvers>
            <mvc:version-resolver>
                <mvc:content-version-strategy patterns="/**"/>
            </mvc:version-resolver>
        </mvc:resolvers>
    </mvc:resource-chain>
</mvc:resources>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM