【发布时间】:2011-11-18 04:05:50
【问题描述】:
正在运行
Tomcat:v6
Spring 工具套件: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:匹配的通配符是严格的,但找不到元素“mvc:annotation-driven”的声明。 app-servlet.xml /app/www/WEB-INF
cvc-complex-type.2.4.c:匹配通配符是严格的,但找不到元素“mvc:resources”的声明。 app-servlet.xml /app/www/WEB-INF
已知问题
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 不包含元素资源
如果替换成http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd还是不行,根据spring 3.05的jar文件可能不工作
mvc:resources 出现在 spring v3.0.4 中,但没有新的 xsd
问题
如何修复编译错误以使 mvc:resources 正常工作?
我已经为此挖掘了大约 2 个小时,还没有可靠的答案......
【问题讨论】:
-
我不认为在 xsd 声明中使用版本是可取的。如果没有给出版本,Spring 将在项目的依赖项中使用最高版本。
标签: java xml spring servlets schema