Spring 报错:元素 "context:component-scan" 的前缀 "context" 未绑定的问题解决
程序员文章站
2024-03-12 09:56:08
spring 配置文件报错:元素 "context:component-scan" 的前缀 "context" 未绑定,这是我在做项目的时候遇到的,经过项目经理及同事提醒解...
spring 配置文件报错:元素 "context:component-scan" 的前缀 "context" 未绑定,这是我在做项目的时候遇到的,经过项目经理及同事提醒解决了,这里就说下如何解决。
1.spring配置信息如下
<?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"> <!-- 自动扫描dao和service包(自动注入) --> <<span style="color: #ff00ff;">context:</span>component-scan base-package="com.makelove88.**.dao,com.makelove88.**.service" /> <import resource="classpath*:*/applicationcontext-*.xml" /> </beans>
2.错误信息如下
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" 未绑定。 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; 元素 "context:component-scan" 的前缀 "context" 未绑定。 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) ... 22 more 十一月 09, 2016 10:09:32 上午 org.apache.catalina.core.standardcontext listenerstart 严重: exception sending context initialized event to listener instance of class org.springframework.web.context.contextloaderlistener
【问题分析】
配置文件中使用了context标签,但未声明。
【解决方案】
在配置文件中加上context的声明
<?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> "> <!-- 自动扫描dao和service包(自动注入) --> <context:component-scan base-package="com.makelove88.**.dao,com.makelove88.**.service" /> <import resource="classpath*:*/applicationcontext-*.xml" /> </beans>
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!