如何从Spring页面转到Spring MVC中的静态页面,因为我收到错误

时间:2015-09-22 10:44:56

标签: xml spring spring-mvc

-if

收到错误

  

匹配的通配符是严格的,但是找不到元素'mvc:resources'的声明。

1 个答案:

答案 0 :(得分:0)

包含<mvc:resources>标记的spring-config XML文件应包含mvc名称空间,如下所示:

<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

注意:有时会引发这样的异常,因为版本号包含在命名空间中,所以请尝试这样:

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

如果您使用 Maven 和依赖项,则需要在项目中或spring-webmvc内添加pom.xml jar文件 (版本号很重要,您应该确保您在项目中使用的所有其他org.springframework罐子/依赖项与此版本号匹配)

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.1.4.RELEASE</version>
</dependency>