xml 元素“context:component-scan”的前缀“context”未绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7131479/
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
The prefix "context" for element "context:component-scan" is not bound
提问by Muhammad Imran Tariq
I am working on spring3 mvc and came up with this error
我正在研究 spring3 mvc 并提出了这个错误
org.xml.sax.SAXParseException: The prefix "context" for element "context:component-scan" is not bound.
org.xml.sax.SAXParseException:未绑定元素“context:component-scan”的前缀“context”。
Here is my dispatcher servlet
这是我的调度程序 servlet
<?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: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-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">
<mvc:annotation-driven />
<context:component-scan base-package="com.web" />
回答by Muhammad Imran Tariq
Such type of error comes when You're missing the xmlns:context declaration but you have declared it. Check your classes in "com.web"package for any wrong coding.
当您缺少 xmlns:context 声明但您已声明它时,就会出现此类错误。检查"com.web"包中的类是否有任何错误的编码。
回答by Emad Abdelhamid
Sometime the problem is in forgetting to add namespace. you should do that in the wizard of creating the config file or in the name space tab after it been created. select the proper namespaces, in this case should be context, and save.
有时问题在于忘记添加命名空间。您应该在创建配置文件的向导中或在创建后的命名空间选项卡中执行此操作。选择适当的命名空间,在这种情况下应该是上下文,然后保存。
回答by Shreya Srivastava
Add the following in the beans of dispatcher-servlet.xml file itself :
在 dispatcher-servlet.xml 文件本身的 bean 中添加以下内容:
so your file looks like :
所以你的文件看起来像:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.Project_name.Controller"></context:component-scan>
</beans>
回答by user11418431
You may lost this profile which is : xmlns:context="http://www.springframework.org/schema/context".
Please write it.
您可能会丢失此配置文件,即:xmlns:context="http://www.springframework.org/schema/context"。请写下来。
回答by Remigius Alwin C
When you're create spring-configuration.xml file you can follow these steps.After enter the name click "Next" now so many check boxes available the you can select 'bean','mvc','context','p'.no need to select downstairs shows some check boxes.because it will select default settings which is your eclipse/spring support.
创建 spring-configuration.xml 文件时,您可以按照以下步骤操作。输入名称后单击“下一步”,现在有很多复选框可用,您可以选择“bean”、“mvc”、“上下文”、“p” .无需选择楼下显示一些复选框。因为它将选择默认设置,即您的 eclipse/spring 支持。
Thanks,
谢谢,

