【问题标题】:mapping resources from context从上下文映射资源
【发布时间】:2012-07-16 04:15:24
【问题描述】:

我想根据上下文将我的文件夹映射到资源文件夹中 例如,在 context.xml 中(我想从 src/main/resources 映射文件)

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="alwaysUseFullPath" value="true"/>
    <property name="mappings">
        <props>
            <prop key="/resources/**">staticResources</prop>
        </props>
    </property>
</bean>

<bean id="staticResources" class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
    <property name="locations">
        <list>
            <value>classpath:/resources/myFolder/</value>
            <value>/resources/</value>
        </list>
    </property>
</bean>

myFolder 中有很多带有文件的子文件夹和更多的子文件夹 但萤火虫说错误 404 并且找不到此类资源

【问题讨论】:

    标签: java spring servlets contextpath


    【解决方案1】:

    最好通过mvc命名空间来做这件事——

    <mvc:resources location="/resources/,classpath:/resources/myFolder" mapping="/resources/**" />
    

    那么你的静态资源应该可以从http://serverurl/contextpath/resources/*访问

    【讨论】:

      猜你喜欢
      • 2015-02-26
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-13
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多