正在运行
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 个小时,还没有可靠的答案......
最佳答案
在您的 spring 上下文中,xml mvc 命名空间 url 应该与 schemaLocation 中的 url 匹配。像这样的:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/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-3.0.xsd">
这是一个标准的 XML 命名空间声明。命名空间 url 是一种唯一的 id,然后映射到 xsi:schemaLocation 中的实际模式位置。
关于java - Spring v3 找不到元素 'mvc:resources' 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436224/