Spring 报错:元素 "context:component-scan" 的前缀 "context" 未绑定的问题解决

作者:lqh 时间:2023-09-10 07:45:34 

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>

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

标签:Spring,报错,context....
0
投稿

猜你喜欢

  • Java DWR内存泄漏问题解决方案

    2022-02-28 02:35:07
  • C#实现洗牌游戏实例

    2021-07-07 00:45:29
  • 浅谈java多态的实现主要体现在哪些方面

    2023-08-17 07:41:32
  • Android实现蒙板效果

    2021-08-30 16:06:04
  • Java基于正则实现的日期校验功能示例

    2021-09-30 02:43:26
  • c#3.0实现延迟赋值示例

    2023-01-04 16:28:51
  • Java设计模式中组合模式应用详解

    2022-08-01 01:51:53
  • 10道springboot常见面试题

    2023-09-02 03:02:22
  • java使用dom4j解析xml配置文件实现抽象工厂反射示例

    2022-11-10 15:45:38
  • Mybatis中注入执行sql查询、更新、新增及建表语句案例代码

    2023-03-07 18:53:55
  • C#控制台输出进度和百分比的实例代码

    2021-10-01 23:49:43
  • mybatis-plus自动生成代码的示例代码

    2023-08-04 22:38:32
  • Android动画 实现开关按钮动画(属性动画之平移动画)实例代码

    2023-01-02 23:06:30
  • Android 自定义返回按钮的实例详解

    2023-07-04 01:13:43
  • android使用SoundPool播放音效的方法

    2023-07-08 01:16:29
  • Android Volley框架使用源码分享

    2023-09-10 09:43:44
  • C#中Action和Func的区别

    2023-10-20 01:30:08
  • Maven的生命周期与自定义插件实现方法

    2022-04-06 20:13:48
  • Java实现英文猜词游戏的示例代码

    2023-08-07 11:40:39
  • SpringMVC+Shiro的基本使用及功能介绍

    2021-11-26 13:12:40
  • asp之家 软件编程 m.aspxhome.com