Spring error: The prefix "context" of element "Context:component-scan" unbound problem resolution _java

Source: Internet
Author: User

Spring configuration File Error: Element "Context:component-scan" prefix "context" unbound, This is what I encountered in the project, after the project manager and colleagues to solve the problem, here on how to solve.

1.spring configuration information is as follows

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= 
"Http://www.springframework.org/schema/beans" 
  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.xsd "> 
 
  <!--automatically scans DAO and service packs (automatic injection)--> 
  <<span style= "color: #ff00ff;" >context:</span>component-scan base-package= "Com.makelove88.**.dao,com.makelove88.**.service"/> 
  <import resource= "classpath*:*/applicationcontext-*.xml"/> 
 
 
</beans> 

2. The error message is as follows

Org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:Line 8 in XML document from URL [file:/e:/ Installsoftware/tomcat/tomcat7u50_8888/webapps/jms/web-inf/classes/applicationcontext.xml] is invalid; Nested exception is org.xml.sax.SAXParseException; Linenumber:8; columnnumber:109; 
  The prefix "context" of the element "Context:component-scan" is not bound. At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( xmlbeandefinitionreader.java:399) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions (Xmlbeandefinitionreader.java : 336) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( xmlbeandefinitionreader.java:304) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:181) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:217) at Org.sPringframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( abstractbeandefinitionreader.java:188) at Org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions ( xmlwebapplicationcontext.java:125) at Org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions ( xmlwebapplicationcontext.java:94) at Org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory ( abstractrefreshableapplicationcontext.java:129) at Org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory ( abstractapplicationcontext.java:537) at Org.springframework.context.support.AbstractApplicationContext.refresh ( abstractapplicationcontext.java:452) at 
  Org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext (contextloader.java:403) At Org.springframework.web.context.ContextLoader.initWebApplicationContext (contextloader.java:306) at Org.sprinGframework.web.context.ContextLoaderListener.contextInitialized (contextloaderlistener.java:106) at Org.apache.catalina.core.StandardContext.listenerStart (standardcontext.java:4961) at Org.apache.catalina.core.StandardContext.startInternal (standardcontext.java:5455) at Org.apache.catalina.util.LifecycleBase.start (lifecyclebase.java:150) at org.apache.catalina.core.containerbase$ Startchild.call (containerbase.java:1559) at Org.apache.catalina.core.containerbase$startchild.call ( containerbase.java:1549) at Java.util.concurrent.FutureTask.run (futuretask.java:262) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1145) at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:615) at Java.lang.Thread.run ( thread.java:745) caused by:org.xml.sax.SAXParseException; Linenumber:8; columnnumber:109; 
  The prefix "context" of the element "Context:component-scan" is not bound. At Com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParSeexception (errorhandlerwrapper.java:198) at Com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError (errorhandlerwrapper.java:177) at Com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (xmlerrorreporter.java:441) at Com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (xmlerrorreporter.java:368) at Com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (xmlerrorreporter.java:325) at Com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement ( xmlnsdocumentscannerimpl.java:289) at com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$ Fragmentcontentdriver.next (xmldocumentfragmentscannerimpl.java:2786) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next (xmldocumentscannerimpl.java:606) at Com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next (xmlnsdocumentscannerimpl.java:117) at Com.sun.org.apache.xerces.internal.impl.XMLDocumentFRagmentscannerimpl.scandocument (xmldocumentfragmentscannerimpl.java:510) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (xml11configuration.java:848) at Com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse (xml11configuration.java:777) at Com.sun.org.apache.xerces.internal.parsers.XMLParser.parse (xmlparser.java:141) at Com.sun.org.apache.xerces.internal.parsers.DOMParser.parse (domparser.java:243) at Com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse (documentbuilderimpl.java:347) at Org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument (defaultdocumentloader.java:76) at 
  Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument (xmlbeandefinitionreader.java:429) At Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( xmlbeandefinitionreader.java:391) ... More November 09, 2016 10:09:32 a.m. Org.apache.catalina.core.StandardContext Listenerstart YanHeavy: Exception sending context initialized event to listener instance of class Org.springframework.web.context.ContextLoade 
 Rlistener

"Problem Analysis"

The context label was used in the configuration file but not declared.

"Solution"
add a context declaration to a configuration file

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= 
"Http://www.springframework.org/schema/beans" 
  xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" 
<span style= "color: #ff00ff;" > xmlns:context= "http://www.springframework.org/schema/context"  
</span>  
  xsi:schemalocation= " Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
<span style= "color: #ff00ff;" >    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd 
</span>    "> 
 
  <!--automatic scanning DAO and service packs (automatic injection)--> 
  <context: Component-scan base-package= "Com.makelove88.**.dao,com.makelove88.**.service"/> 
  <import resource= " classpath*:*/applicationcontext-*.xml "/> 
 
 
</beans> 

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.