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

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
报错:元素
spring mvc 前缀、spring mvc 前缀后缀、spring mvc 统一前缀、springmvc url前缀、spring context,以便于您获取更多的相关知识。

时间: 2024-10-28 02:51:54

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

spring 报错,求高手解答

问题描述 spring 报错,求高手解答 代码: package com.test.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annota

代码-spring报错 mismatched input &amp;amp;#39;gt&amp;amp;#39; expecting EOF

问题描述 spring报错 mismatched input 'gt' expecting EOF 代码如下: <?xml version="1.0" encoding="UTF-8"?> xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util

【web.xml】报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

今天搭建新的项目,虽然在web.xml中配置了ContextLoaderListener以及IntrospectorCleanupListener 如下: web.xml中部分代码: 1 <!-- 监听servletContext,启动contextConfigLocation中的spring配置信息 --> 2 <listener> 3 <listener-class>org.springframework.web.context.ContextLoaderListe

Spring报错:expected at least 1 matching bean还是没解决

问题描述 严重: Exception sending context initialized event to listener instance of class cn.tg.core.web.ApplicationListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'systemConfigMngImpl': Autowiring of methods

关于json存值报错 Servlet.service() for servlet [default] in context with path [/examin

问题描述 这个json问题里到底存在多少种错误情况现在以本人经验发现对象中存在date类型或存在对象中还有对象这两种情况会导致这种错误出现.这问题字面上是存在多个回应,在第一个回应已经结束也会导致这个错误.这个问题有什么解决方案,存在的情况也请大神详细说明一下,最近被这问题缠绕多天了.感谢大家鼎力相助!! 解决方案 解决方案二:没看懂你想表达什么解决方案三:好像有属性设置你不需要转的.解决方案四:引用1楼wobuxiangnila的回复: 没看懂你想表达什么 Servlet.service()f

spring-注解扫描和mvc注解扫描放一起报错!

问题描述 注解扫描和mvc注解扫描放一起报错! Spring AOP前置通知案例 这两个注解开启注解扫描 不开启mvc注解一切正常 controller层能正确显示页面 测试方法也能正确测试出aop通知成功!但是开启mvc注解后controller层能正常显示 测试AOP前置通知的方法会报错是为什么? <!-- 开启注解扫描 --> <context:component-scan base-package="com" /> <!-- mvc注解扫描支持@R

exception-容器启动就报错,ssh整合

问题描述 容器启动就报错,ssh整合 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerjava.lang.IllegalArgumentException at org.springframework.asm.ClassReader.(Unknown Source) at org.sp

sqoop从MySQL导入数据到hive报错 class not found

问题描述 sqoop从MySQL导入数据到hive报错 class not found 解决方案 sqoop 导入oracle 报错 Imported Failed : Attempted to generate class with no columns问题解决办法mysql启动报错 MySQL manager or server PID file could not be found! [FAILED]启动HIVE 服务报错 HWI WAR file not found 解决方案二: 您好,

【报错】spring整合activeMQ,pom.xml文件缺架包,启动报错:Caused by: java.lang.ClassNotFoundException: org.apache.xbean.spring.context.v2.XBeanNamespaceHandler

spring版本:4.3.13 ActiveMq版本:5.15 ======================================================== spring整合activeMQ,pom.xml文件缺架包,启动报错: [springDemo][INFO] [2017-12-11 14:54:57] org.springframework.web.context.ContextLoader.initWebApplicationContext(304) | Root