开发者

The prefix "context" for element "context:component-scan" is not bound

I am working on spring3 mvc and came up with this error

org.xml.sax.SAXParseException: The prefix "context" for element "context:component-scan" is not bound.

Here is my dispatcher servlet

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="开发者_JS百科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" /> 


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.


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.


Add the following in the beans of dispatcher-servlet.xml file itself :

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>


You may lost this profile which is : xmlns:context="http://www.springframework.org/schema/context". Please write it.


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.

Thanks,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜