【问题标题】:Why resource file does not load in spring-mvc为什么资源文件没有在spring-mvc中加载
【发布时间】:2019-04-03 09:13:09
【问题描述】:

我在 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>

【问题讨论】:

  • 你能分享你的整个xml文件吗

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


【解决方案1】:

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

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

【讨论】:

  • 谢谢。重新安排映射和位置后,它工作正常...
猜你喜欢
  • 2015-05-25
  • 2018-03-26
  • 2019-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 2020-10-27
相关资源
最近更新 更多