提问者:小点点

Spring MVC 无法识别配置文件中的 mvc:resource


更新:现在工作正常。请关注评论。
这是我的 Spring 配置文件:

<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/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
    ">
    <context:component-scan  base-package="report.frontcontroller"/>
    <mvc:resources mapping="/resources/**" location="/resources/" />
    <mvc:annotation-driven />
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix"> <value>/WEB-INF/</value></property>
        <property name="suffix"> <value>.jsp</value></property>
    </bean>
</beans>

所有jar都包含在这个项目中,配置文件如上所示。我收到此部分的错误:

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />

错误: * 匹配通配符是严格的,但没有找到 mvc:resource 和 mvc:注释的声明 * 在此行找到多个注释: - cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素 'mvc:resources' 的声明。- schema_reference.4:无法读取架构文档“http://www.springframework.org/schema/mvc/spring- mvc-3.0.xsd”,因为 1) 找不到文档;2)文件无法阅读;3) 文档的根元素不是 。 在此行找到多个注释:* - cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素 'mvc:resources' 的声明。- schema_reference.4:无法读取架构文档“http://www.springframework.org/schema/mvc/spring- mvc.xsd”,因为 1) 找不到该文档;2)文件无法阅读;3) 文档的根元素不是 。


共2个答案

匿名用户

你能试试下面从GIT - spring-mvc-showcase复制的配置吗

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <resources mapping="/resources/**" location="/resources/" />

    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <task:annotation-driven />

</beans:beans>

匿名用户

spring-mvc.xsd更改为spring-mvc-3.0.xsd。在所有剩余的位置也进行类似的更改。

参考这里

编辑

   <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="report.frontcontroller" />
    <mvc:annotation-driven/>
    <mvc:resources mapping="/resources/**" location="/resources/" /> 
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/views/" />
      <property name="suffix" value=".jsp" />
   </bean>
</beans>