Spring v3 找不到元素“mvc:resources”的声明;
当前运行的
Tomcat:v6
Spring Tools Suite:v2.7.2
Spring Framework: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 将除 mvc:resources 映射静态文件之外的所有 url 映射到 servlet 。
Bug
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 正常工作?
我已经为此挖掘了大约两个小时,但还没有可靠的答案......
Currently Running
Tomcat: v6
Spring Tools Suite: v2.7.2
Spring Framework: 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 partial code
<servlet-mapping>
<servlet-name>duckapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Servlet Purpose
web.xml maps all urls to the servlet with the exception of mvc:resources mapping static files.
Bugs
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: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'. app-servlet.xml /app/www/WEB-INF
Known Issues
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd doesn't contain the element resource
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 appeared in spring v3.0.4, but has no new xsd
Question
How can I fix the compile errors to get mvc:resources working correctly?
I've been digging around 2 hours for this, no solid answer yet...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 spring 上下文中,xml mvc 命名空间 url 应与 schemaLocation 中的 url 匹配。像这样:
这是一个标准的 XML 命名空间声明。命名空间 url 是一种唯一的 id,然后将其映射到 xsi:schemaLocation 中的实际架构位置。
In your spring context xml mvc namespace url should match url in schemaLocation. Something like this:
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 命名空间 url 时,我通常不使用版本信息,并且
大部分时间都工作得很好。
您可能想尝试命名空间 url
而不是
When using Spring namespaces urls I normally do not use version information and that
works most of the time pretty well.
You might like to try the namespace url
instead of
我遇到了同样的错误。原因是缺少 Maven 依赖项 spring -webmvc。我添加了以下依赖项,它开始工作。
I was getting the same error. The cause was the missing Maven dependency spring -webmvc. I included the below dependency and it started working.
我认为您的 schemaLocation 映射不正确。命名空间被指定为:
我相信这是正确的,但是在 schemaLocation 中你有
所以如果你将 schemaLocation 映射的第一行更改为你的 mvc 命名空间,它应该可以正常工作。
I think your schemaLocation mapping is incorrect. The namespace is specified as:
which is correct, I believe, but in the schemaLocation you have
So if you change the first line of the schemaLocation mapping to your mvc namespace, it should work fine.
我已报名参加 udemy 春季课程。我遵循教练指示我做的每一步。
所以如果你使用 spring mvc 和 hibernate 你可能会遇到这个错误
无法读取架构文档 'http://www.springframework.org/schema/ tx/spring-tx.xsd' 等:
在我的 spring 配置文件中,我
在 xsi:schemaLocation 中有这两个 url,我将其替换为
实际上我访问了这两个站点
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
因此,在我看来,明确指定版本是一个很好的做法。
它对我有用,希望这对你也有用。
谢谢。
I have enroled for spring course on udemy. I followed every step that my instructor show me to do.
So if you are using spring mvc and hibernate you may encounter this error
Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd' etc for:
in my spring configuration file i had these two urls
in xsi:schemaLocation, which i replaced with
actually i visited these two sites
http://www.springframework.org/schema/mvc/ and http://www.springframework.org/schema/tx/
and just added the latest version of spring-mvc and spring-tx i.e, spring-mvc-4.2.xsd and spring-tx-4.2.xsd
So, in my opinion specifying version no explicitly is a good practice.
It worked for me, hope this works for you too.
Thank you.