Spring 配置文件报错:元素 "context:component-scan" 的前缀 "context&am

2016-12-20 19:34:00来源:CSDN作者:piewpip83人点击

【现象】:

    1.spring配置信息如下

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans  
  5.         http://www.springframework.org/schema/beans/spring-beans.xsd">  
  6.   
  7.     <!-- 自动扫描dao和service包(自动注入) -->  
  8.     <<span style="color: #ff00ff;">context:</span>component-scan base-package="com.makelove88.**.dao,com.makelove88.**.service" />  
  9.     <import resource="classpath*:*/applicationContext-*.xml" />  
  10.   
  11.   
  12. </beans>  

     2.错误信息如下

Java代码  收藏代码
  1. 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; 元素 "context:component-scan" 的前缀 "context" 未绑定。  
  2.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:399)  
  3.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)  
  4.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)  
  5.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)  
  6.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)  
  7.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)  
  8.     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)  
  9.     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)  
  10.     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)  
  11.     at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)  
  12.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)  
  13.     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)  
  14.     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)  
  15.     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)  
  16.     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961)  
  17.     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455)  下载
  18.     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)  
  19.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)  
  20.     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)  
  21.     at java.util.concurrent.FutureTask.run(FutureTask.java:262)  
  22.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
  23.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
  24.     at java.lang.Thread.run(Thread.java:745)  
  25. Caused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 109; 元素 "context:component-scan" 的前缀 "context" 未绑定。  
  26.     at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)  
  27.     at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)  
  28.     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)  
  29.     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)  
  30.     at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)  
  31.     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:289)  
  32.     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)  
  33.     at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)  
  34.     at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)  
  35.     at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)  
  36.     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)  
  37.     at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)  
  38.     at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)  
  39.     at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)  
  40.     at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)  
  41.     at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)  
  42.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)  
  43.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)  
  44.     ... 22 more  
  45. 十一月 092016 10:09:32 上午 org.apache.catalina.core.StandardContext listenerStart  
  46. 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener  

【问题分析】

     配置文件中使用了context标签,但未声明。

【解决方案】下载

    在配置文件中加上context的声明

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4. <span style="color: #ff00ff;">  xmlns:context="http://www.springframework.org/schema/context"   
  5. </span>   
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  7. <span style="color: #ff00ff;">        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
  8. </span>        ">  
  9.   
  10.     <!-- 自动扫描dao和service包(自动注入) -->  
  11.     <context:component-scan base-package="com.makelove88.**.dao,com.makelove88.**.service" />  
  12.     <import resource="classpath*:*/applicationContext-*.xml" />  
  13.   
  14.   
  15. </beans> 

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台