当前正在运行
Tomcat:v6
Spring Tools Suite:v2.7.2
Spring框架:spring-webmvc-3.0.5
Servlet XML
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc/spring-mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources" />
<context:component-scan base-package="com.app.mvc" />
</beans>
web.xml部分代码
<servlet-mapping>
<servlet-name>duckapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Servlet目的
web.xml将所有URL映射到servlet,但mvc:resources映射静态文件除外 .
错误
-
cvc-complex-type.2.4.c:匹配的通配符是strict,但是找不到元素'mvc:annotation-driven'的声明 . app-servlet.xml / app / www / WEB-INF
-
cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有找到元素'mvc:resources'的声明 . app-servlet.xml / app / www / WEB-INF
已知问题
-
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd不包含元素资源
-
如果被_2532980替换仍然无效,可能无法正常工作根据spring 3.05的jar文件
-
mvc:资源出现在spring v3.0.4中,但没有新的xsd
问题
如何修复编译错误以使mvc:资源正常工作?
我一直在挖掘大约2个小时,还没有可靠的答案......
5 回答
在您的spring上下文中,xml mvc namespace url应该与schemaLocation中的url匹配 . 像这样的东西:
这是标准的XML命名空间声明 . 命名空间url是一个唯一的id,然后映射到xsi:schemaLocation中的实际架构位置 .
当使用Spring命名空间URL时,我通常不使用版本信息,并且大部分时间都可以正常工作 . 您可能想尝试命名空间URL
代替
我得到了同样的错误 . 原因是缺少Maven依赖性spring -webmvc . 我包含了下面的依赖项,它开始工作了 .
我认为你的schemaLocation映射是不正确的 . 命名空间指定为:
这是正确的,我相信,但在schemaLocation你有
因此,如果您将schemaLocation映射的第一行更改为您的mvc名称空间,它应该可以正常工作 .
我已经为udemy加入了 Spring 季课程 . 我按照我的导师告诉我要做的每一步 . 因此,如果您使用spring mvc和hibernate,您可能会遇到此错误无法读取架构文档'http://www.springframework.org/schema/tx/spring-tx.xsd'等:
在我的 spring 配置文件中,我有这两个网址
在xsi:schemaLocation中,我替换为
实际上,我访问了这两个网站http://www.springframework.org/schema/mvc/和http://www.springframework.org/schema/tx/,并添加了最新版本的spring-mvc和spring-tx,即spring-mvc-4.2.xsd和spring-tx-4.2.xsd
因此,在我看来,明确指定版本是一个很好的做法 . 它对我有用,希望这也适合你 . 谢谢 .