为什么在Spring-MVC中无法加载资源文件

时间:2019-04-03 09:13:10

标签: spring spring-mvc model-view-controller

我在mvc:resource标签下面添加了servlet.xml,但是我的应用程序未获取任何资源文件。我正在尝试开发基于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>

1 个答案:

答案 0 :(得分:1)

here所述,尝试像这样更改映射顺序和位置

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