spring mvc:注释驱动未绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6001593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mvc:annotation-driven is not bound
提问by Pieter
I get this error when I run a certain Spring Web 3 project in NetBeans:
在 NetBeans 中运行某个 Spring Web 3 项目时出现此错误:
org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 30; The prefix "mvc" for element "mvc:annotation-driven" is not bound.
org.xml.sax.SAXParseException; 行号:11;列数:30;元素“mvc:annotation-driven”的前缀“mvc”未绑定。
Here's dispatcher-servlet.xml:
这是dispatcher-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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="net.myproject.controllers"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
I think I did the appropriate namespace declarations, but obviously I'm still overlooking something. Why am I getting this error?
我想我做了适当的命名空间声明,但显然我仍然忽略了一些东西。为什么我收到这个错误?
采纳答案by Bozho
It should work like that, and it works for me. The problem might be in your IDE / xml editor. Try ignoring the xml error and run the application.
它应该像那样工作,它对我有用。问题可能出在您的 IDE/xml 编辑器中。尝试忽略 xml 错误并运行应用程序。
回答by jaipster
This is an IDE Error, Which can be resolved by following to
这是一个IDE错误,可以通过以下方式解决
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:mvc="http://www.springframework.org/schema/mvc"


回答by Ahmed
try this it worked for me:
试试这个它对我有用:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.mkyong.common.controller" />
<mvc:annotation-driven />
回答by Yavvari Pradeep
This is an IDE Error, Which can be resolved by adding the following to your Spring Dispatcher Servlet
这是一个 IDE 错误,可以通过将以下内容添加到 Spring Dispatcher Servlet 来解决
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
And also add the following snippet if it is not included in your xml file
如果您的 xml 文件中未包含以下代码段,请添加以下代码段
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
回答by Avnish
Changing below code worked for me
更改以下代码对我有用
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
to below code (imp : check xmlns:context and xmlns:xsi position)
到下面的代码(imp:检查 xmlns:context 和 xmlns:xsi 位置)
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
回答by enrique
You are probably missing some significant portion of the namespace declaration, as discussed here: http://forum.springsource.org/showthread.php?100397-The-prefix-mvc-for-element-mvc-annotation-driven-is-notbound
您可能遗漏了命名空间声明的一些重要部分,如下所述:http: //forum.springsource.org/showthread.php?100397-The- prefix-mvc-for-element-mvc-annotation-driven-is-未绑定
It does not effect runtime, but the development environment will suffer with similar problems as you describe.
它不会影响运行时,但开发环境会遇到与您描述的类似问题。
I guess it should go this way: http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
我想它应该这样:http: //www.springframework.org/schema/aop/spring-aop-3.0.xsd
回答by user1595577
Add: xmlns:p="http://www.springframework.org/schema/p"
添加:xmlns:p="http://www.springframework.org/schema/p"
Otherwise xml will not understand the p annotation.
否则 xml 将无法理解 p 注释。

