首页 > 解决方案 > 为什么资源文件没有在spring-mvc中加载

问题描述

我在 servlet.xml 中添加了 mvc:resource 标记,但我的应用程序没有获取任何资源文件。我正在尝试开发基于 xml 的 spring mvc 应用程序。为什么资源文件没有加载?

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean name="/welcome.htm" 
        class="com.debasish.common.controller.HelloWorldController" />
    <mvc:resources location="/resources/" mapping="/test/**"></mvc:resources>
    <mvc:annotation-driven></mvc:annotation-driven>
</beans>

标签: springspring-mvcmodel-view-controller

解决方案


如前所述尝试像这样更改映射和位置的顺序

<mvc:resources mapping="/client/**" location="/optimized-scripts/visualize/" />
<mvc:annotation-driven />

推荐阅读