0

私のdispatcher.xmlは、以下のようにリソースチェーンを設定します:

<mvc:resources location="/static/" mapping="/static/**" cache-period="31536000">
        <mvc:resource-chain resource-cache="true">
            <mvc:resolvers>
                <!--<bean class="org.springframework.web.servlet.resource.GzipResourceResolver"/>-->
                <bean class="org.springframework.web.servlet.resource.CachingResourceResolver">
                    <constructor-arg ref="staticResourceCache"/>
                </bean>
                <bean class="org.springframework.web.servlet.resource.VersionResourceResolver">
                    <property name="strategyMap">
                        <map>
                            <entry key="/**">
                                <bean class="org.springframework.web.servlet.resource.ContentVersionStrategy"/>
                            </entry>
                        </map>
                    </property>
                </bean>
                <bean class="org.springframework.web.servlet.resource.PathResourceResolver"/>
            </mvc:resolvers>
            <mvc:transformers>
                <bean class="org.springframework.web.servlet.resource.CachingResourceTransformer">
                    <constructor-arg ref="staticResourceCache"/>
                </bean>
                <bean class="org.springframework.web.servlet.resource.CssLinkResourceTransformer">
                    <!--<property name="allowedLocations" value="/static"> </property>-->
                </bean>
            </mvc:transformers>
        </mvc:resource-chain>
    </mvc:resources>

コードをデバッグすると、リソース チェーンに 2 つの PathResourceResolver があることがわかりました。 ResourceHttpRequestHandler の状態

4

2 に答える 2

0

spring-mvc-4.3.xsd にメモが存在することがわかりました。

<xsd:documentation source="org.springframework.web.servlet.config.annotation.ResourceChainRegistration"><![CDATA[
Assists with the registration of resource resolvers and transformers.
Unless set to "false", the auto-registration adds default Resolvers (a PathResourceResolver) and Transformers
(CssLinkResourceTransformer, if a VersionResourceResolver has been manually registered).
The resource-cache attribute sets whether to cache the result of resource resolution/transformation;
setting this to "true" is recommended for production (and "false" for development).
A custom Cache can be configured if a CacheManager is provided as a bean reference
in the "cache-manager" attribute, and the cache name provided in the "cache-name" attribute.
        ]]></xsd:documentation>
于 2016-12-14T12:13:16.827 に答える
0

PathResourceResolverSpring がデフォルト id のデフォルト Bean を追加していると思われますpathResourceResolver。明示的に 1 つを宣言していますが、id がないため、最終的には 2 になります
。Spring Framework はこれを頻繁に行います。同じ ID の Bean を指定しない限り、デフォルトの Bean が作成されます。

この理論は次の方法でテストできます:
1) 構成からコメントアウトしますPathResourceResolverか? 1で終わりますか?
2)PathResourceResolver設定で your を使用しますが、id を指定しpathResourceResolverますか? 1で終わりますか?

于 2016-12-14T09:26:52.653 に答える