Spring v3 找不到元素“mvc:resources"的声明 [英] Spring v3 no declaration can be found for element 'mvc:resources'
问题描述
Tomcat: v6
Spring 工具套件:v2.7.2
Spring Tools Suite: v2.7.2
Spring 框架:spring-webmvc-3.0.5
Spring Framework: spring-webmvc-3.0.5
<?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 映射静态文件除外.
Servlet Purpose
web.xml maps all urls to the servlet with the exception of mvc:resources mapping static files.
cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素mvc:annotation-driven"的声明.app-servlet.xml/app/www/WEB-INF
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element '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
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'. app-servlet.xml /app/www/WEB-INF
如果替换为 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 仍然无法工作,并且根据 spring 3.05 的 jar 文件可能无法工作
If replaced by http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd still doesn't work and may not be working according to jar files of spring 3.05
mvc:resources 出现在 spring v3.0.4,但没有新的 xsd
mvc:resources appeared in spring v3.0.4, but has no new xsd
如何修复编译错误以使 mvc:resources 正常工作?
How can I fix the compile errors to get mvc:resources working correctly?
我已经为此挖掘了大约 2 个小时,还没有可靠的答案......
I've been digging around 2 hours for this, no solid answer yet...
推荐答案
在你的 spring 上下文中,xml mvc 命名空间 url 应该与 schemaLocation 中的 url 匹配.像这样:
In your spring context xml mvc namespace url should match url in schemaLocation. Something like this:
<?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 中的实际模式位置.
This is a standard XML namespace declaration. The namespace url is sort of an unique id, which is then mapped to the actual schema location in xsi:schemaLocation.
这篇关于Spring v3 找不到元素“mvc:resources"的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!